如何在 ContextMenu 下设置子菜单的样式?
这是 ContextMenu 的代码:
<ListView.ContextMenu>
<fw:AcrylicContextMenu Style="{StaticResource NowPlayingContextMenuStyle}" ItemContainerStyle="{StaticResource NowPlayingContextMenuItemStyle}">
<MenuItem>
<MenuItem.Header>
<TextBlock Text="Play" Style="{StaticResource NowPlayingContextMenuItemHeader}" />
</MenuItem.Header>
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Play" />
</MenuItem.Icon>
</MenuItem>
<!-- ... -->
<MenuItem>
<MenuItem.Header>
<TextBlock Text="Sort" Style="{StaticResource NowPlayingContextMenuItemHeader}" />
</MenuItem.Header>
<MenuItem.Icon>
<materialDesign:PackIcon Kind="Sort" />
</MenuItem.Icon>
<!--#region SubMenu Sort-->
<MenuItem>
<MenuItem.Header>
<TextBlock Text="Ascending" Style="{StaticResource NowPlayingContextMenuItemHeader}" />
</MenuItem.Header>
<MenuItem.Icon>
<materialDesign:PackIcon Kind="SortAscending" />
</MenuItem.Icon>
</MenuItem>
<MenuItem>
<MenuItem.Header>
<TextBlock Text="Descending" Style="{StaticResource NowPlayingContextMenuItemHeader}" />
</MenuItem.Header>
<MenuItem.Icon>
<materialDesign:PackIcon Kind="SortDescending" />
</MenuItem.Icon>
</MenuItem>
<!--#endregion SubMenu Sort-->
</MenuItem>
</fw:AcrylicContextMenu>
</ListView.ContextMenu>
样式是这样定义的:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:V_Player.Resources.Styles"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes">
<Style x:Key="NowPlayingListViewItemStyle" BasedOn="{StaticResource MaterialDesignListBoxItem}" TargetType="ListViewItem">
<Setter Property="Height" Value="32" />
<Setter Property="Padding" Value="8,8,8,8" />
</Style>
<Style x:Key="NowPlayingContextMenuStyle" BasedOn="{StaticResource MaterialDesignMenu}" TargetType="ContextMenu">
<Setter Property="Foreground" Value="White" />
<Setter Property="Opacity" Value="0.7" />
<Setter Property="FontSize" Value="14" />
<Setter Property="MinWidth" Value="128" />
</Style>
<Style x:Key="NowPlayingContextMenuItemStyle" BasedOn="{StaticResource MaterialDesignMenuItem}" TargetType="MenuItem">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="8, 0, 8, 0" />
</Style>
<Style x:Key="NowPlayingContextMenuSeparatorStyle" BasedOn="{StaticResource MaterialDesignSeparator}" TargetType="Separator">
<Setter Property="Margin" Value="0" />
<Setter Property="Padding" Value="0" />
<Setter Property="Height" Value="1" />
</Style>
<Style x:Key="NowPlayingContextMenuItemHeader" BasedOn="{StaticResource MaterialDesignTextBlock}" TargetType="TextBlock">
<Setter Property="Margin" Value="-12, 0, 0, 0" />
</Style>
</ResourceDictionary>
结果并不完全正确......当然对于子菜单。
菜单背景是亚克力和透明的,但子菜单没有,它是灰色的,具有材料设计风格。
我能做些什么来修复它?