1

We need to replace the context menu for the RibbonButton items, and suppress the context menu everywhere else. We have succeeded in replacing the context menu with nothing at the top level:

 <ribbon:Ribbon x:Name="ribbon" ItemsSource="{Binding RibbonItems}">
        <ribbon:Ribbon.ContextMenu>
            <ribbon:RibbonContextMenu>
            </ribbon:RibbonContextMenu>
        </ribbon:Ribbon.ContextMenu>
    </ribbon:Ribbon>

(Note that the Ribbon is populated programmatically, not explicitly in xaml.)

We have replaced the RibbonButton context menu:

<DataTemplate DataType="{x:Type local:ControlData}">
<ribbon:RibbonButton>
    <RibbonButton.Template>
        <!-- snip -->
    </RibbonButton.Template>
    <RibbonButton.ContextMenu>
        <RibbonContextMenu>
            <MenuItem Header="Help" Command="{Binding HelpCommand}" />
        </RibbonContextMenu>
    </RibbonButton.ContextMenu>
</ribbon:RibbonButton>

We haven't figured out how to suppress the Context menu in the area around the menu items (pink in the pic below): enter image description here

Edit: Here is the context menu that appears when clicking in the empty space around the menu items: enter image description here

Any ideas would be appreciated....

Number8
  • 12,322
  • 10
  • 44
  • 69

3 Answers3

0

To hide the default quick access toolbar one must provide a faux one and then handle the message when it opens it as such

<ribbon:Ribbon Title="Ribbon Me">
   <ribbon:Ribbon.QuickAccessToolBar>
      <ribbon:RibbonQuickAccessToolBar ContextMenuOpening="QuickContextMenuOpening">
         <DockPanel>
            <ribbon:RibbonButton Label="faux"  />
         </DockPanel>
      </ribbon:RibbonQuickAccessToolBar>
   </ribbon:Ribbon.QuickAccessToolBar>

Code Behind

private void QuickContextMenuOpening(object sender, ContextMenuEventArgs e)
{
    e.Handled = true;
}
ΩmegaMan
  • 29,542
  • 12
  • 100
  • 122
0

Set the ContextMenu property of the RibbonGroup to null. Depending on how your Ribbon is defined, you could do this for all groups using an implicit Style that you add to the Resource dictionary of the Ribbon:

<Ribbon x:Name="ribbon" ..>
    <Ribbon.Resources>
        <Style TargetType="RibbonGroup">
            <Setter Property="ContextMenu" Value="{x:Null}" />
        </Style>
    </Ribbon.Resources>
</Ribbon>
mm8
  • 163,881
  • 10
  • 57
  • 88
  • Weird -- when I add that Style in none of the content of the ribbon displays.... Maybe that is somehow related to using the ItemsSource property on Ribbon? – Number8 Jun 20 '19 at 16:08
0

It looks like it this simple:

    <!-- RibbonGroup -->
    <Style TargetType="{x:Type ribbon:RibbonGroup}" BasedOn="{StaticResource RibbonControlStyle}">
        <!-- snip -->
        <Setter Property="ContextMenu" Value="{x:Null}" />
     </Style>

Thanks mm8 for posting ContextMenu = null in a property setter in Resources....

Number8
  • 12,322
  • 10
  • 44
  • 69