How can I completely customize popup from MenuItem?
I have normal menu in XAML. And I would like to completely change looks of the popup that gets displayed when you click on menu item.
I'm looking for something like this:
<Menu>
<MenuItem Header="MyCustomMenu">
<MenuItem.PopupTemplate>
<ControlTemplate>
<Image Source="SexyImage"/>
</ControlTemplate>
开发者_如何学运维 </MenuItem.PopupTemplate>
</MenuItem>
</Menu>
You need to override the template of the MenuItem
since the Popup is a part of it, have a look at the default templates to get an idea of what a template should look like. MenuItem
has a TemplatePartAttribute
for said popup.
Define following styles in resources of your application:
An example of style overriding for MenuItem:
<Style TargetType="MenuItem">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="MenuItem">
.... here is your custom template
ContextMenu styles overriding:
<Style TargetType="ContextMenu">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Grid.IsSharedSizeScope" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ContextMenu">
精彩评论