I hope someone can clarify the situation I have below.
I have a simple CustomControl style based on a Button in a ResourceDictionary named SHButtonStyle.xaml
<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>
I also have a ResourceDictionary named Brushes as below:
<SolidColorBrush x:Key="Background" Color="Red"/>
I also have a Themes folder with Generic.xaml which has the MergedDictionaries as below:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/TestCustomControl;component/SHButtonStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
I have tried merging the ResourceDictionary for the Brushes within the Generic.xaml as I understood it is best to merge all ResourceDictionary's within Generic.xaml?
But the only way I can get this to work is with an additional MergedDictionaries for the Brushes within the SHButtonStyle.xaml. Is this correct or what am I missing when merging the ResourceDictionary's within the Generic.xaml.
Thank you in advance for your assistance
Either merge the brushes resource dictionary in theme/generic.xaml directly, or merge them both at global level in
App.xaml:The
MergedDictionariesof themes/generic.xaml usually contains "standalone" resource dictionaries for custom controls without any dependencies to resources in other resource dictionaries.