Using Commands to Provide User Interface Elements
Commands can provide user interface elements such as labels, images, and screen tip data to any control that uses them. Doing this requires the implementation of the IRibbonCommandUIProvider interface.
If your commands inherit RibbonCommand (which inherits RoutedCommand
), they are already set up with properties and methods that support user interface provisioning. Properties such as Label, ImageSourceLarge, etc. can be used to supply any attached controls with those user interface elements.
Now sometimes there are existing commands that you want to use which don't inherit RibbonCommand. No problem, by registering an existing command with the RibbonCommandUIManager, any command can provide user interface elements.
Say that you wanted the WPF framework EditingCommands.ToggleBold
command to provide user interface elements to any control that uses it. You would register the command at the startup of your application like this:
RibbonCommandUIManager.Register(EditingCommands.ToggleBold,
new RibbonCommandUIProvider("Bold", null, "pack://application:,,,/SampleBrowser;component/Images/Bold16.png", "Make the selected text bold."));
What happens is that RibbonCommandUIManager ties the command to the RibbonCommandUIProvider that you pass. Note that the RibbonCommandUIProvider implements IRibbonCommandUIProvider just like RibbonCommand does.
Be sure to use full pack:// syntax so that the created BitmapImage
can be frozen to prevent possible memory leaks.