WPF ContextMenu子菜单样式

问题描述 投票:0回答:1

我已经因ContextMenu样式问题而停留了两天。我正在寻找一种解决方案,以更改ContextMenu下的od 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>

结果也不完全正确...当然是子菜单。

菜单背景为亚克力和透明,但子菜单为否,它为灰色并具有材料设计样式。

enter image description here

我该如何解决?

wpf xaml material-design contextmenu acrylic-material
1个回答
0
投票

我认为您可以在此主题中找到答案:

WPF Submenu styling

© www.soinside.com 2019 - 2024. All rights reserved.