WPFwiki, wpf, wiki, .net 3.0, windows presentation foundation, FAQ, free resources, solution, development, microsoft Home of the world's largest WPF FAQ
Edit

Category

Resources

Edit

Question

How can I specify different styles and templates for different Themes/Color Schemes for my custom controls?

Edit

Answer

There are two options:

You can place the Theme/Color Scheme resources in the assembly containing the custom control.

OR

You can place the Theme/Color Scheme resources in an external assembly.

For the first option, you need to set the first parameter of the [assembly: ThemeInfo()] attribute located in the "properties/AssemblyInfo.cs" file of your project to the ResourceDictionaryLocation.SourceAssembly value.

For the second option, the same parameter for the same attribute needs to be set to the ResourceDictionaryLocation.ExternalAssembly value. This will cause the theme/color scheme to be searched in a separate assembly, named after the source assembly and the theme.

The format of the name for the ExternalAssembly is "source_assembly_name.theme_name.dll"

Examples:

For a source assembly called "CustomControls.Buttons.dll"

CustomControls.Buttons.Luna.dll
CustomControls.Buttons.Royale.dll

Then, for either of the two options:

In the required assembly (source or external), you need to create a new ResourceDictionary, contained in its own independent XAML file, for each theme/color scheme you want to support.

You must name each of these files after the theme/color scheme it represents.

The format for the filename is "formal_theme_name.formal_color_scheme_name.xaml"

Examples:

luna.normalcolor.xaml
luna.homestead.xaml
luna.metallic.xaml
royale.normalcolor.xaml

Also, you must place the file in a "themes" folder directly in the assembly's project root (same location as the "generic.xaml" file when using ResourceDictionaryLocation.SourceAssembly).

All content is Copyright ©2007 Xceed Software Inc. unless otherwise indicated. See the Terms of Service. Contributors must read and agree to the Contribution Policy. WPFwiki is brought to you by Xceed, makers of the powerful yet free Xceed DataGrid for WPF.