我无法扩展我在 Windows 字典中定义的一种样式。单独,它似乎按预期将样式应用于我的控件。但是,如果尝试使用 basedOn 属性在我的一个用户控件中扩展样式,它只会覆盖主要样式,并且所有基本样式都会消失。这是一个例子:
在名为 dict1.xaml 的资源字典中:
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Pink"/>
</Style>
在主 window.xaml 中:
<Window.Resources>
<ResourceDictionary Source="dict1.xaml"/>
</Window.Resources>
在名为 userControl1.xaml 的用户控件中:
<UserControl.Resources>
<Style BasedOn="{StaticResource {x:Type Button}}"
TargetType="{x:Type Button}">
<Setter Property="FontWeight" Value="Bold"/>
</Style>
</UserControl.Resources>
用户控件中的样式简单地覆盖资源字典中的样式,字体为粗体。如果我删除用户控件中的样式,字典中的样式就会生效并且背景变成粉红色。我两个都想要。