我希望有人能澄清我在下面的情况。
我有一个基于名为 SHButtonStyle.xaml 的 ResourceDictionary 中的按钮的简单 CustomControl 样式
<Style TargetType="{x:Type local:SHButton}">
<Setter Property="Background" Value="{StaticResource ResourceKey= Background}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:SHButton}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我还有一个名为 Brushes 的 ResourceDictionary,如下所示:
<SolidColorBrush x:Key="Background" Color="Red"/>
我还有一个带有 Generic.xaml 的 Themes 文件夹,它的 MergedDictionaries 如下:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/TestCustomControl;component/SHButtonStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
我已经尝试在 Generic.xaml 中合并画笔的 ResourceDictionary,因为我知道最好在 Generic.xaml 中合并所有 ResourceDictionary?
但是我可以让它工作的唯一方法是在 SHButtonStyle.xaml 中为画笔添加一个额外的 MergedDictionaries。这是正确的还是在 Generic.xaml 中合并 ResourceDictionary 时我遗漏了什么。
预先感谢您的帮助