Here is how you can create a theme after our last release.
First it's a good idea to base the theme on one of our existing themes instead of starting form zero. You can find the xaml files for our themes in the distribution packages. In the attached project I have added the Windows7
theme to use as example. Note that the Windows7
theme is not referenced anywhere in the main project. It's added to the solution so we can easily copy/paste in our custom theme.
Now to create a theme
you will need to reference the Telerik.Windows.Controls.dll because the Theme class is there. Our custom themes have some constants hardcoded so they can easily be accessed from xaml. If you are about to create your custom theme you will need to create an Instance of Theme and set it's Source
property... Now most people want to create custom class instead of creating Theme instance with it's Source set to xaml file. So you can check how to create a custom theme class in the CustomTheme project
in the attached example. There is a class called CustomTheme.cs
which defines a source to xaml file:
CustomTheme : Theme
Note that when you create an instance of CustomTheme
now the Theme's Source
will be automaically set in the CustomTheme
Now let's see what should be within the /Themes/CustomThemeGeneric.xaml file. Our themes use ResourceDictionaries
to search for the styles for the controls and if they find a proper style they will attach it to the control (by setting the control's Style property in Silverlight). If a style is not present in the dictionary the control will fallback to the default Office_Black. In the example I wanted to use RadComboBox
. So the CustomThemeGeneric.xaml
had to contain definitions for these two styles. The easiest way is to include the xaml files for these controls (I copy-pasted them from the Windows7 included theme) and modify them.
Note that if you miss a resource in the xaml file or mispell the path to the generic you will get errors. Also the example contains definitions for controls in Telerik.Windows.Controls.Input so the custom theme project needs references to the Input dll. If you are about to add more controls you will need to reference the proper dlls.
Once You have extended the Theme class, set it's source to dictionary with styles and included the proper styles your theme will be ready to use the theme. How to apply it? In the CustomWindows7Theme
project in the attached solution I'm using the CustomTheme
. Note that CustomWindows7Theme references the CustomTheme project as well as the Telerik.Windows.Controls.dll and the Telerik.Windows.Controls.Input.dll. All I need to set an application theme is to create an instance of the CustomTheme
class and point the style manager to the instance:
// Set the application theme before the InitializeComponent
Telerik.Windows.Controls.Theme appTheme =
Telerik.Windows.Controls.StyleManager.ApplicationTheme = appTheme;
Note that this is done in the App.xaml.cs before InitializeComponent(). If you set application theme after you create the controls the theme won't take effect.
Also if you don't want to create a custom theme you can add it in the Resources:
And use the StyleManager
to set a theme to a single control:
I hope this works for you.
the Telerik team