Before you proceed reading this topic we recommend you read the Xaml vs. NoXaml article.
The Telerik UI for WPF suite provides a variety of themes that will help you achieve outstanding visual appearance and great user experience. Before choosing what theme to apply you might find it useful to familiarize with the themes concept and the difference between Xaml and NoXaml.
A theme contains all the styles and resources needed for the visualization of the Telerik controls. Each theme consists of multiple XAML files. You can think of each separate file as a collection of compliant styles which are needed for the visualization of a certain control. As most of the custom controls are quite complex and contain other custom controls within themselves, often you will need the resources of several files.
There are two mechanisms that can be used to set a theme.
Using implicit styles gives you full Blend support and smaller dlls size. To use this mechanism you will need to use the NoXaml version of the UI for WPF dlls.
To change the theme you will need to take the following few steps.
Reference the NoXaml version of the Telerik UI for WPF dlls. They can be found in the */Telerik UI for WPF installation folder/Binaries.NoXaml/* folder.
Get the .xaml files with the control styles and templates.
There are two options to get the .xaml files.
- Reference the theme dll from the /Binaries.NoXaml/ folder - for example Telerik.Windows.Themes.Office_Black.dll. The theme dll contains ResourceDictionary files with the styles for the controls.
- Copy the XAML files in a dedicated folder in your application. You can get the files from the /Telerik UI for WPF installation folder/Themes.Implicit/ folder.
Merge the required .xaml files in the App.xaml file.
In the implicit styles (NoXaml) scenario you will need to merge the resources for each referenced dll. For example, to use RadGridView you will need to reference the following dlls.
And then merge the dictionaries for the controls in the dlls as shown in Example 1.
Example 1: Merging .xaml files for the Office_Black theme (from the theme dll)
<Application> <Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/System.Windows.xaml"/> <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.xaml"/> <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.Input.xaml"/> <ResourceDictionary Source="/Telerik.Windows.Themes.Office_Black;component/Themes/Telerik.Windows.Controls.GridView.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources> </Application>
Note that the
Telerik.Windows.Data.dlldoesn't have any UI (controls) so it doesn't have a ResourceDictionary with styles and templates.
Merging the .xaml files in App.xaml will apply the theme to all controls in the application. To apply the theme only for a specific view you can merge the dictionaries in its Resources. For example, in the
<UserControl.Resources></UserControl.Resources>. To apply the theme only for a specific control you can merge the dictionaries in the Resources of the control's parent container.
Keep in mind that, when creating custom controls or styles based on Telerik controls you will need to use their base styles. Read more about this in the Styling the Controls article.
You can find all required .xaml files in two places, respectively you can use two approaches to reference them in the project.
Reference theme dll
All styles and templates for the themes are encapsulated in theme dlls located in the /Binaries.NoXaml/ folder (Telerik.Windows.Themes.Material.dll, Telerik.Windows.Themes.Office2016.dll, etc.). To get the styles for a specific theme you can just merge its ResourceDictionaries directly from the theme assembly. For example, if you are using the Office_Black theme, you should add a reference to the Telerik.Windows.Themes.Office_Black.dll and then merge the needed .xaml files as shown in Example 1 .
We recommend this approach because upgrading and maintaining is easier. The other one (copying the XAML files) is better if you have highly customized controls or you use only several controls and don't want to include a dll with all styles.
Copy the XAML files in a dedicated folder in your application
The default styles and resources for each theme are shipped also in the /Telerik UI for WPF installation folder/Themes.Implicit folder. In order to apply a certain theme for your application you can copy all the required XAML files from the respective theme's folder (depends on the set of controls you are using) in a folder from your application. And then merge the ResourceDictionaries in the application's MergedDictionaries collection. You should merge all .xaml files corresponding to each assembly reference you have in your project, as shown in Example 2 and Figure 1.
Figure 1: Copy the needed XAML files in a separate folder in your application
Example 2: The MergedDictionaries in your application resources:
<Application.Resources> <ResourceDictionary> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="/Themes/System.Windows.xaml"/> <ResourceDictionary Source="/Themes/Telerik.Windows.Controls.xaml"/> <ResourceDictionary Source="/Themes/Telerik.Windows.Controls.Input.xaml"/> <ResourceDictionary Source="/Themes/Telerik.Windows.Controls.GridView.xaml"/> </ResourceDictionary.MergedDictionaries> </ResourceDictionary> </Application.Resources>
If you merge a ResourceDictionary for a dll that is missing from the project's References an error will occur.
You should not set application theme using the StyleManager when using implicit styles.
If you copy the XAML files in your project, please make sure that the .xaml files are with the proper build action. Generally it should be Resource, except for the Telerik.Windows.Controls.RibbonView.xaml file where the build action should be Page. Telerik.Windows.Controls.RichTextBoxUI.xaml also should be with build action Page since it includes all RibbonView styles. This is caused by several x:Shared setters, which cannot be set in loose XAML. More information can be found in MSDN.
StyleManager is used when working with the standard (Xaml) dlls. The StyleManager is a class that applies different styles on the Telerik controls based on the set theme. It allows you to set the theme on a control level and on application level.
To change the theme via the StyleManager you will need to take the following few steps.
Reference the Xaml version of the Telerik UI for WPF dlls. They can be found in the /Telerik UI for WPF installation folder/Binaries/ folder.
Set the StyleManager.Theme attached property on the control you want to theme. Or set the StyleManager.ApplicationTheme static property before calling the InitializeComponent method of the view or the App.xaml.cs file. This will set the theme globally for all Telerik controls.
Example 3: Setting the theme on a control level
StyleManager.SetTheme(radControlInstance, new Office2016Theme());
StyleManager.SetTheme(radControlInstance, New Office2016Theme())
Example 4: Setting the theme on application level
StyleManager.ApplicationTheme = new Office2016Theme(); InitializeComponent();
StyleManager.ApplicationTheme = New Office2016Theme() InitializeComponent()
Read more about this approach in the StyleManager help section.
Merging theme resource dictionaries when using StyleManager (mixing implicit styles theming and StyleManager) is not supported. Use StyleManager only with Xaml dlls, or Implicit Styles only with NoXaml binaries.
All Themes are specifically designed to style Telerik controls. However, there are some native Microsoft WPF controls which are affected by the theming mechanism as well. You can find a list of these controls in the Setting a Theme on MS Controls article.