I have a control library that consists of only UserControl derived controls. I am using a third party created assembly to ‘skin’ my controls. In a regular WPF application project all i need to do is merge a resource dictionary from the assembly in Application.xaml:
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary Source="/ThirdPartyAssembly;component/SomeSkin.xaml" />
</Application.Resources>
</Application>
I have tried acheiving the same affect by adding the resource dictionary to Generica.xaml in my control library:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/ThirdPartyAssembly;component/SomeSkin.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
But that doesn’t work. From what I have been reading it seems this approach only works with controls that derive from Control?
I have tried/checked the following:
- I have this assembly attribute:
<Assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)> - My Generic.xaml file is in the /Themes folder
- I have tried overiding the DefaultStyleKey in the static constructor – but this just blanks everything out (probably because I do not have styles created for each specific control)
Is there away for me to skin my controls without having to add the resource dictionary to every single control in my library?
At the end of the day I am hosting my WPF user controls in a WinForms application – so i am not able to use the obvious approach of setting the skin in Application.xaml as I would if I were using the controls from a WPF application.
Make sure that
Generic.xamlis correctly referred in theResourcessection of the topmostUserControlyou have hosted in your windows form.I personally think that themes apply to anything that derives from
Control, so alsoUserControl(asUserControlitself derives fromControl).I have tested steps 1 and 2 above and my user control applied the thems corerctly when hosted in my windows form.
Having said that, I have not tried applying any Third party tool (external assembly) based Theme. So that is something I am not sure about….
Will let you know if I can get
infragistics(3rd party) themes applied to my user control in a WindowsFormsHost. But the key is that the topmost UserControl in your WindowsFormsHost must refer the theme in it.Do share your thoughts if tips above do not work.