Connect a RibbonCommand to an existing ICommand?

Nov 4, 2008 at 4:50 PM
Is there any simple way to connect a RibbonCommand to an existing ICommand instance, or will I have to add Execute & CanExecute handlers in code-behind that forward through to the original?

The two scenarios I'm thinking of:
  1. Using the built in commands: System.Windows.Input.ApplicationCommands.Copy, et al
  2. Using a DelegateCommand<T> in Prism (Composite Application Guidance for WPF)
Nov 4, 2008 at 6:20 PM

Hi James,

Currently there is no built-in way to use an existing ICommand instance in RibbonCommand - this a feature which we are designing now and will add in V1.  The two scenarios you mentioned are some of the main scenarios we are considering, so you should be able to do this in V1.  For now, however, you'll have to add Execute & CanExecute handlers.

If you have any requests or recommendations for how you'd like this feature to work in V1, please let us know as we will definitely consider your input while finalizing our designs.


Nov 5, 2008 at 8:12 AM
Great to hear you've got this targeted for V1.

What I was initially looking for was something like a "Command" property (or perhaps "ContainedCommand", "NestedComand" or similar). That's not something I've thought about at any length though.

It will be important for us to be able to get the existing ICommand through binding, though. It may well be exposed on the PresentationModel as a property, as we're using Prism. The PresentationModel could have defined the command itself or it might have got it from a service or controller class. It will likely be a DelegateCommand<T>, with Execute/CanExecute handlers already attached.


Nov 7, 2008 at 4:16 PM

I actually spent the entire morning looking for that functionality :-)

As a workaround, how can I call the application commands copy functionality manually using C#?

Nov 25, 2008 at 8:44 PM
Like Tarazi, I am looking to forward the ribbon command's executed call to the application commands. I have not been able to get this to work.

Anybody have a working example of how to do this?
Nov 25, 2008 at 9:37 PM
Okay, I may have found a workable solution. I am a newby with C#, so this may not be the best way to do this.

Say in the ribbon command you have Executed="OnNewFile", then the following codebehind seems to work:

        private void OnNewFile(object sender, ExecutedRoutedEventArgs e)
            RoutedCommand command = ApplicationCommands.New;
            command.Execute(sender, null);

Feb 5, 2009 at 1:19 PM
It does not work for me for some reason; it loses the focus from the selected text when I click on the ribbon button.

I still have a lot of work to do before my application goes live, I think by then there will be a new beta from the ribbon

Thank you
Feb 5, 2009 at 2:55 PM
Hi Tarazi,

that is a known issue with this version of the ribbon:

I have the same slack in my timing, so like you I am hoping a new beta will be out before I need to release my product.


Feb 5, 2009 at 3:02 PM
Us too. I think we better hope that we get the full release of the ribbon before we need to ship, though. The license precludes shipping the betas.

Note that when I asked about this situation, I found out that the whole RibbonCommand architecture is (most likely) going away.