【发布时间】:2021-05-14 19:06:33
【问题描述】:
我想通过定义明暗模式的样式来修改按钮的颜色。我的样式定义如下:
<Style x:Key="ExampleButton" TargetType="Button">
<Setter Property="FontSize" Value="14" />
<Setter Property="FontWeight" Value="Normal" />
</Style>
在另一个文件中,我已将 ButtonBackground 定义为浅色模式下的“红色”。我的期望是当我的应用程序使用这个 ExampleButton 时,它应该有一个红色背景。但是,我仍然可以使用它的默认 BorderBackground 看到这个按钮,即 SystemControlBackgroundBaseLowBrush。我可以通过 3 种方式解决这个问题:
-
将 SystemControlBackgroundBaseLowBrush 重新定义为“Red”,这可行,但我可能会将 SystemControlBackgroundBaseLowBrush 用于其他控件,所以不想使用这种方法。
-
在上面的代码中添加另一个 setter 并有类似的东西
<Style x:Key="ExampleButton" TargetType="Button"> <Setter Property="FontSize" Value="14" /> <Setter Property="FontWeight" Value="Normal" /> <Setter Property="Background" Value="Red"/> </Style> -
编辑按钮模板中的值
实现这一目标的最优雅的解决方案是什么?除了我上面描述的3个之外,还有更好的解决方案吗?
我希望避免添加整个模板来修改颜色
【问题讨论】:
-
你的进展如何?如果您的问题已经解决,您可以标记有用的答案,这将有助于其他面临相同问题的人。