I'm working on WPF Window Application which uses ContextMenu
.
My ContextMenu
in XAML (in Window.Resources):
<ContextMenu x:Key="menuList" Placement="Bottom" >
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Header" Value="{Binding Name}"/>
<EventSetter Event="Click" Handler="cm_RefreshChannelNotification"/>
<Setter Property="IsChecked" Value="{Binding CFiltered}" />
<Setter Property="IsCheckable" Value="True"/>
<Setter Property="StaysOpenOnClick" Value="True"/>
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
When I try to add Separator to the ContextMenu
I receive error:
System.InvalidOperationException was unhandled Message="A style intended for type 'MenuItem' cannot be applied to type 'Separator'.
In this way I must add a new separator:
ContextMenu cm = this.FindResource("menuList") as ContextMenu;
Separator separator = new Separator();
separator.SnapsToDevicePixels = true;
cm.Items.Add(separator);
What should I change/add in ContextMenu
definition to make it work?