如何更改WPF对控件的默认样式的想法?为什么这首先发生?在下面的XAML中,我声明了一个Style for Button,然后进一步声明一个新的Style,它覆盖了一个名为"HugeBut"的setter . 我希望HugeBut是隐含的基于我新的未命名的风格,但显然它不是;
<Window.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="Red">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<!-- badness -->
<Style TargetType="{x:Type Button}" x:Key="HugeBut">
<Setter Property="Foreground" Value="Yellow"/>
</Style>
<!-- works, but I do not want to explicitly set the based-on. -->
<Style TargetType="{x:Type Button}" x:Key="HugeBut" BasedOn="{StaticResource {x:Type Button}}">
<Setter Property="Foreground" Value="Yellow"/>
</Style>
</Window.Resources>
<Button Content="Regular" />
<Button Content="huge!" Style="{StaticResource HugeBut}"/>
您可能会看到两个红色按钮,一个带有黑色文本,另一个带有黄色,但Style HugeBut继承了我在未命名样式中未指定的所有值,这些值来自Button的系统默认主题(在我的案例中为Aero) .
我该怎么做才能改变这种行为?
2 回答
似乎答案在这里:
http://wpfthemereplacer.codeplex.com/
从网站描述:
这正是我正在寻找的 . 这将允许我使用样式,因为它们旨在用于广泛“重新主题化”的应用程序,而不是通过设置全局样式进行主题化(然后处理追踪缺少的代码的一些代码)由于WPF错误和其他限制,或根本无法处理它)
好吧,如果你不想,我不知道你需要的框架并不在乎 .