I have a customized Menu and MenuItems and each MenuItem has an specific command bound to it. My problem is that when I click on any MenuItem, the command executes but the Menu is not closed.
Here's an example of the Menu with one MenuItem
<Menu Background="#f4f4f4" x:Name="ExportMenu">
<Menu.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" Background="#f4f4f4"/>
</ItemsPanelTemplate>
</Menu.ItemsPanel>
<MenuItem x:Name="CopyItem" Header="Copy" Style="{DynamicResource MainMenuItem}"
CommandParameter="{Binding Data.CurrentPlotVMs, Source={StaticResource Proxy}}"
Command="{Binding Data.ExporterVM.CopyGraphicPlotsCommand, Source={StaticResource Proxy}}" Click="CopyItem_Click">
<MenuItem.Icon>
<TextBlock Text="" FontSize="15" FontFamily="../Icons/#icons"/>
</MenuItem.Icon>
</MenuItem>
</Menu>
And here's my customized style
<Style x:Key="MainMenuItem" TargetType="{x:Type MenuItem}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="FontFamily" Value="Open Sans"/>
<Setter Property="FontSize" Value="12"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontWeight" Value="Light"/>
<Setter Property="StaysOpenOnClick" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MenuItem}">
<Border x:Name="templateRoot" BorderThickness="0" Background="#f4f4f4" SnapsToDevicePixels="True" Padding="0,10,10,10">
<Grid VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ContentPresenter x:Name="Icon"
Grid.Column="0"
Content="{TemplateBinding Icon}"
ContentSource="Icon"
HorizontalAlignment="Center" Height="16" Width="16"
Margin="5,0,5,0"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="Center"/>
<ContentPresenter ContentTemplate="{TemplateBinding HeaderTemplate}"
Content="{TemplateBinding Header}"
Grid.Column="1"
ContentStringFormat="{TemplateBinding HeaderStringFormat}"
ContentSource="Header"
Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="templateRoot" Property="Background" Value="{StaticResource ResourceKey=FrSkyBlue}"/>
<Setter Property="Foreground" Value="{StaticResource FrWhite}"/>
<Setter Property="Cursor" Value="Hand"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Maybe I'm setting wrong a property or doing something else wrong, I'm kinda new to WPF and MVVM.