Reputation: 5556
Suppose I have App.xaml
with following content:
[...]
<Application.Resources>
<Style TargetType="{x:Type CheckBox}">
<Setter Property="BorderBrush" Value="{StaticResource Theme.CheckBox.Border}" />
<Setter Property="Foreground" Value="{StaticResource Theme.Foreground}" />
</Style>
</Application.Resources>
[...]
Now, I want to move those definitions to external assembly. This way I can reuse WPF controls and window styles across my applications. For example I could create NuGet package and install those styles in seconds.
Upvotes: 2
Views: 300
Reputation: 9944
You can create a simple classLibrary
project, Define all your styles and templates etc, in separated resource dictionaries (recommended) and merge all those dictionaries into one dictionary.
To use those styles from that specific assembly just refer to it in your App.Xaml file,
The following shots should gave you a global view
I am used to create a separate ResourceDictionary
for each style
(for easy access), and all those resource dictionaries are merged in the ResourceLibrary.Xaml
Now to refere to that ControlLibraryAssembly (after adding a reference to it), in your app.xaml file add
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ControlLibrary;component/ResourcesDictionaries/ResourceLibrary.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Upvotes: 3
Reputation: 160
You need to make resource assembly. Here you can read how you can create it: https://msdn.microsoft.com/en-us/library/aa984332(v=vs.71).aspx
Upvotes: 1