1
votes

I have this very simple ControlTemplate:

<ControlTemplate TargetType="{x:Type ContextMenu}">
                    <Border 
                           Name="Border"
                           Background="{StaticResource BlueBackground}"
                           BorderBrush="LightBlue"
                           CornerRadius="10"
                           BorderThickness="1" >
                        <StackPanel IsItemsHost="True"/>
                    </Border>
                </ControlTemplate>

I made it to create a nifty jawdroppingly beautiful rounded corner! However, when I point the mouse over a contextmenu a MouseOver Trigger fires from somewhere that draws a terribly ugly nearly square border on top of my nifty rounded border!

Where is it coming from??

EDIT: The most likely cause is that the ContextMenu is an ItemsControl that holds MenuItems, even when my ContextMenu holds a single UserControl. So the UserControl is seen as a MenuItem and highlighted when the IsMouseOver==true! What is the easiest way to disable this behaviour?

1
Have you got anything interesting in that StackPanel? What about adding some padding to the Border element, to see if it makes a difference.Jay
I did that and it does, hence the edit.Dabblernl

1 Answers

0
votes

You can set the ItemContainerStyle property of your ContextMenu to a custom style for MenuItems.

<ContextMenu.ItemContainerStyle>
    <Style
        TargetType="MenuItem">
        <Setter
            Property="Template">
            <Setter.Value>
                <ControlTemplate
                    TargetType="MenuItem">
                    <TextBlock
                        Text="{TemplateBinding Header}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ContextMenu.ItemContainerStyle>

With this strategy you have to make your own triggers for any mouse over effects you want, but Click and Checked events will still fire normally.