Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Completely Custom Context Menu

I am trying to create a completely custom context menu for a touch application with a radial style ("pie slices" for each item). I have been able to create one from with a base of ItemsControl. However, when I try to switch this to a base of ContextMenu, I cannot get rid of the default pop-up with each pie slice in a list of items.

Is there any way to override the default ContextMenu style to get rid of this items list functionality?

Edit: This is a screen shot of my problem. The code is almost the exact same between the two examples, other than what class is inherited from and how it displays (adding as a child to a Canvas vs. showing the popup)

Top: The custom context menu inheriting from ItemsControl. Bottom: The same context menu inheriting from ContextMenu

Edit 2: I tried overriding the default style as below:

<ContextMenu.Style>
  <Style TargetType="ContextMenu">
    <Setter Property="OverridesDefaultStyle" Value="true" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="ContextMenu">
          <Canvas IsItemsHost="true" Height="100" Width="100" />
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>
</ContextMenu.Style>

The context menu when overriding the default style.

like image 661
Sarah Avatar asked Jul 16 '26 04:07

Sarah


1 Answers

If you just want to change appeareance of a WPF control, just change its controltemplate.

Here is the default one for ContextMenu : http://msdn.microsoft.com/en-us/library/ms744758.aspx

And do not forget to update the MenuItem controltemplate too : http://msdn.microsoft.com/en-us/library/ms747082(v=vs.85).aspx

like image 158
mathieu Avatar answered Jul 18 '26 19:07

mathieu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!