Assembly-wide / root-level styles in WPF class library
Try adding
Style={DynamicResource MyStyle}
You cannot use a StaticResource in this case.
This sounds like a job for theming.
- Add a
/themes/generic.xaml
ResourceDictionary to your project. - Add the following to AssemblyInfo.cs:
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
- ?
- Profit!
Any resources you add to generic will be used by all controls. Also you can make profile specific themes (Luna, Aero etc.) by including a ResourceDictionary file with the correct theme name in the themes
directory.
Heres a link to more info: Create and apply custom themes
If you dont have an app.xaml, you can still load it into the appplication-level resources, but you have to write code (not xaml) to do it, similar to this...
void LoadIt(){ ResourceDictionary MyResourceDictionary = new ResourceDictionary(); MyResourceDictionary.Source = new Uri("MyResources.xaml", UriKind.Relative); App.Current.Resources.MergedDictionaries.Add( MyResourceDictionary )}
check out this site for an example: http://ascendedguard.com/2007/08/one-of-nice-features-about-wpf-is-how.html