Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Created July 13, 2012 08:33
Show Gist options
  • Save pinzolo/3103668 to your computer and use it in GitHub Desktop.
Save pinzolo/3103668 to your computer and use it in GitHub Desktop.
[WPF]コンテキストメニューのバインディングにてセパレータを動的に生成する
<ContextMenu ItemsSource="{Binding Menus}">
<ContextMenu.ItemContainerStyle>
<Style TargetType="{x:Type MenuItem}">
<Setter Property="Header" Value="{Binding Title}" />
<Setter Property="Command" Value="{Binding Command}" />
<Setter Property="IsEnabled" Value="{Binding IsEnabled}" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsSeparator}" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Separator Style="{StaticResource {x:Static MenuItem.SeparatorStyleKey}}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</ContextMenu.ItemContainerStyle>
</ContextMenu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment