Custom RibbonCommand?

Mar 17, 2009 at 12:35 PM
I am creating an app that uses the Ribbon control. I have encapsulated the Ribbon in a UserControl, to keep its markup and resources separated from those of the host window. I would like to create a custom RibbonCommand for each item on the ribbon, like this:

<r:RibbonCommand x:Key="Copy"
    ToolTipDescription="Copy the selection and put it on the Clipboard."
    ToolTipTitle="Copy" />

 I can place 'Executed' and 'CanExecute' handlers in the UserControl's code-behind, and they work okay.

But that's not what I want to do. What I want is for the RibbonCommand to bubble up the logical tree so that the window hosting the UserControl can respond to it. I know that I need to set a CommandBinding in the host window, and I know generally how to do that. But I'm not sure how to reference a custom RibbonCommand in the UserControl from the host window. Can someone tell me how to do that?

BTW, I'm aware that RibbonCommands are probably going away in v1 of the Ribbon control. I'm simply trying to get the current version of the control wired up using the existing infrastructure.

Thanks for your help.

David Veeneman
Foresight Systems

Mar 18, 2009 at 2:22 AM
I found my answer. I won't belabor things here. A RibbonCommand is declared in code pretty much the same way as a custom RoutedCommand--declare it in a static class, add it to the CommandBindings collections of both the UserControl and the main window. The 'executed' and 'can execute' methods get specified in the main window's CommandBinding, since that's who will respond to the command. The RibbonCommand type has properties for label, images, tool tip, and keyboard gesture--so those properties get set in code, rather than in XAML.

David Veeneman
Foresight Systems