I'm trying to place my WPF styles in a separate library, but at a little lost as to how this is best achieved. This is what I've done thus far:
- Created a new Class Library project and added references PresentationCore, PresentationFramework, System.Xaml and WindowsBase
Created file "MyStyles.xaml" in this class library project with the following content:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style TargetType="Button" x:Key="MyButtonStyle"> <Setter Property="Background" Value="Transparent"/> </Style> </ResourceDictionary>
Built the project.
Created a new WPF application project, and referenced the library built above.
In App.xaml attempted to reference the resource dictionary in the libarary as follows:
`<ApplicationResources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="pack://application:,,,/MyCustomWpfStyles;component/MyStyles.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary>
`
At this point VS intellisense is telling that an error occurred while finding the resource dictionary, although the application builds without problem.
Even if I am able to load the resource dictionary, I'm not sure how to use it with a control, e.g.,
<Button Style="What goes here??" />
Looked over the internet, but can't seem to find a good example of how to package styles up into separate dll. Any pointers?