MenuItem Style 似乎被覆盖了

MenuItem Style seems to be overwritten

当我使用 ItemContainerStyle 时,我尝试使用的菜单项样式似乎被完全覆盖了。

以下是我使用它时发生的情况的示例:

然而,当我不使用它时,这是我得到的:

我更喜欢第二个菜单的外观,但是由于没有使用ItemContainerStyle,它不支持动态创建菜单。什么可能会覆盖样式?我正在使用 Mahapps Dark base 和 VS colors/styles.

您应该在 ItemContainerStyle 中使用 BaseOn 属性。

<ItemContainerStyle x:Key="MyContainerStyle" BaseOn="{DynamicResource MenuItemStyle}">Style here</ItemContainerStyle>

将您的自定义 Style 基于 MahApps 附带的 MetroMenuItem 样式:

<Style TargetType="MenuItem" BasedOn="{StaticResource MetroMenuItem}">
    <Setter Property="Background" Value="Yellow" />
</Style>