I have a context menu with the following items
<ContextMenu x:Name="NotificoContextMenu" x:Shared="false" x:Key="SysTrayMenu" x:FieldModifier="public" Loaded="NotificoContextMenu_Loaded" Style="{DynamicResource conte}">
<MenuItem Header="Connect" x:Name="ConnectMenuItem" x:FieldModifier="public" />
<MenuItem Header="Ping" Command="{Binding PingCommand}"/>
<MenuItem Header="Show Window" Command="{Binding ShowWindowCommand}" />
<Separator />
<MenuItem Header="Exit" Command="{Binding ExitApplicationCommand}" />
</ContextMenu>
For the ConnectMenuItem im adding menuitems in it from code
I have an style for the contextmenu it applys to all the menu items exept the ones i add from code what should I do
This is the style for my context menu
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style TargetType="{x:Type ContextMenu}" x:Key="conte">
<Setter Property="Background" Value="{DynamicResource PrimaryDark}" />
<Setter Property="Foreground" Value="{DynamicResource Secendery}" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="HasDropShadow" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ContextMenu}">
<Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Foreground}" BorderThickness="0.5" CornerRadius="5">
<StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="HasDropShadow" Value="true">
<Setter TargetName="Border" Property="Padding" Value="0,3,0,3" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
found some souloution while searching day and night for it here is the full windows resourses file :