There are a WPF User Control library and two (or more) User Controls in it. I need to use the same style in both user controls. How can I share this style?
For example:
This is the style:
<Style x:Key="customLabelStyle" TargetType="Label">
...
</Style>
User control A:
<UserControl x:Class="Edu.Wpf.Example.UserControlA"
...xmlns stuff... >
<Grid>
... some xaml markup...
<Label Style="{StaticResource customLabelStyle}"/>
</Grid>
</UserControl>
UserControl B:
<UserControl x:Class="Edu.Wpf.Example.UserControlB"
...xmlns stuff... >
<Grid>
... some another xaml markup...
<Label Style="{StaticResource customLabelStyle}"/>
</Grid>
</UserControl>
So how can I share this style between user controls in the library without involving of the application app.xaml resource dictionary?
UPDATE
I can add Themes\Generic.xaml into my library and define the style there. But in this case I have to use ComponentResourceKey as the key of the style. Right? It’s long and not very handy expression…
You can define the shared resources in a separate
ResourceDictionary, then merge them into yourUserControl‘s Resources using MergedDictionaries.