Is there an easy way to allow a user to right click on a ribbon button, and select "Add to Quick Access Toolbar"?
Nov 19, 2008 at 6:43 PM
You would just need to implement a ContextMenu with an item for "Add to Quick Access Toolbar" and when the user selects that item, you would want to create a copy of the control that the user had clicked on (for example, if it was a RibbonButton,
just create a new button and assign the same command to it) and add the control to the Quick Access Toolbar with the Placement attached property set to InToolbar.
If you need help implementing this, let me know.
Dec 3, 2008 at 11:57 PM
In case anyone would like an example, I wrote a quick sample showing how to do this:
In the XAML:
<MenuItem Header="Add to Quick
Access Toolbar" Click="AddToQAT"/>
In the code behind:
void AddToQAT(object sender,
// Step 1 - Find out what type of control is being added to the QAT
Type controlType = ((ContextMenu)((MenuItem)sender).Parent).PlacementTarget.GetType();
// Do a check for each control type in your Ribbon to determine what type the sending control is
// This is an example of how to do it for RibbonButton
if (controlType ==
// Step 2 - Clone the control
// 2A - Once you know the type, create a new instance of that type
RibbonButton newButton =
// 2B - Assign the same RibbonCommand to the new instance of the control as is used on the original instance.
// This will make sure that the controls have the same visual and command properties
newButton.Command = ((RibbonButton)((ContextMenu)((MenuItem)sender).Parent).PlacementTarget).Command;
// Step 3 - Add the new control to the QuickAccessToolBar
// Other Considerations
// - Control states. You may need to make sure that the control states are in sync. For example, if you have toggle buttons, the toggle state
// of the control on the QAT should be the same as the corresponding control on the Ribbon.
// - Serialization. You may want to serialize the controls in the QAT so that the same ones appear the next time the user opens the application
// - Scalability. In this case, we've defined the ContextMenu on the control itself, but in a real-world scenario, this approach doesn't really scale.
// Instead, what you'd want to do is to set the ContextMenu at the Ribbon level. However, this will break the check for the control type, since
// PlacementTarget will always return Ribbon. To find the control that was clicked, you can handle the PreviewMouseUp event and use it in the
// context menu handler.
void RibbonCommand_CanExecute(object sender,
void RibbonCommand_Executed(object sender,
Are there any examples or guidance on how to serialize the QAT?