WPF ContextMenu Стиль подменю - PullRequest
       56

WPF ContextMenu Стиль подменю

0 голосов
/ 19 апреля 2020

Я застрял с проблемой стиля ContextMenu в течение двух дней. Я ищу решение изменить стиль ContextMenu под 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>

И результаты не совсем правильные ... Для подменю, конечно.

Фон меню Acryli c и прозрачный, но подменю нет, он серый и имеет дизайн материала стиль.

enter image description here

Что я могу сделать, чтобы исправить это?

...