【问题标题】:MenuItem Style seems to be overwrittenMenuItem 样式似乎被覆盖了
【发布时间】:2017-06-09 07:41:03
【问题描述】:

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

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

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

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

【问题讨论】:

  • 你试过ItemContainerStyleStyle上的BasedOn属性吗?

标签: c# wpf xaml mahapps.metro


【解决方案1】:

基于MetroMenuItem 附带的MetroMenuItem 样式@ 自定义Style

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

【讨论】:

  • 感谢您的回答!我将我的项目设置为在 app.xaml 中使用 MahApps,因此样式将是全局的。任何线索为什么这不会自动基于此?
  • 为什么会这样?这不是隐式风格的工作原理。
【解决方案2】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 2010-11-29
    • 1970-01-01
    相关资源
    最近更新 更多