This is a migrated thread and some comments may be shown as answers.

Loading multiple themes for similar controls

2 Answers 191 Views
Themes and Visual Style Builder
This is a migrated thread and some comments may be shown as answers.
Adrian Bennett
Top achievements
Rank 1
Adrian Bennett asked on 08 May 2009, 05:14 AM
Hi,

Ive got a complex MDI application which Im trying to theme. Ive tried a few different ways to create multiple themes that the user can chose between and the only way I can get it to work is if I create a ControlDefault theme for most controls, and any controls that need to be different, like panels that need to show different colours I create a separate theme file and set the ThemeName property on the panels to match up the the correct theme. Then to swap between themes I have a different set of files with the same ThemeNames. 

This works great, but I cant figure out how to unload a theme, also if I have 2 themes, light and dark and the form loads with the light theme, then I set it to dark, if I try to set it back to light it wont apply. How can I unload the theme, or properly switch between themes?

To load the themes Im using ThemeResolutionService.RegisterThemeFromStorage(...);

Also

Ive built a control which inherits from RadPanel, and when I try and theme it, the theme will not apply. I had a look at the resulting xml from the Visual Style Builder, and it was setting the ControlType attribute in the RadStylesheetRelation node to RadPanel instead of my class. I manually set this to my class and it worked fine. While this works, it is a pain, and if the client wants to create new themes later they will need to manually change the xml.

Any help would be appreciated
Thanks

2 Answers, 1 is accepted

Sort by
0
Accepted
Mike
Telerik team
answered on 08 May 2009, 02:15 PM
Hello Adrian Bennett,

Generally there are two approaches for managing themes in your application, however in both cases you have to load the theme (files) only once and then apply different themes to the controls in your app by managing the ThemeName property of the corresponding controls or ThemeResolutionService.ApplicationThemeName - if you what to apply the same theme to all controls in the application. Because of possible performance issues ThemeResolutionService loads the same theme file only once, no matter how many times you call RegisterTheme(...) methods. Actually, there is a way to workaround this behavior, however, I would not recommend you should use it. Let me know if you choose this approach though and I'll prepare a sample application for you.

Here are some tips that can help you with application theming without the need to load theme files each time you need different theme.

The following article describes the approach using ApplicationThemeName:
http://www.telerik.com/help/winforms/themes_using_a_default_theme_for_the_entire_application.html

This of course requires that all controls in the application have consistent style corresponding to the ThemeName selected. The article also describes how you can override the default ApplicationThemeName behavior for specific control instances that you can apply in the case with the panels that should have different looks in you app. However I would recommend you use this as little as possible and try to handle specific cases by manipulating contorls' ThemeClassName property that you are already familiar with.

The other way to batch change the ThemeName of controls in your applicaiton is to use the method:
ThemeResolutionService.ApplyThemeToControlTree(container, "ThemeName"),
where the container could be a Form for example. This will change the theme name of all controls in the specified container (Control).

There is a pretty simple solution to the problem with your RadPanel-inherited control. You should override the ThemeClassName property in the following way:

public override string ThemeClassName 
    get 
    { 
        return typeof(RadPanel).FullName; 
    } 
    set 
    { 
        //nothing to do in this case
    } 

Please, take a look at the following KB article for details:
http://www.telerik.com/support/kb/winforms/general/inherit-themes-from-radcontrols.aspx

Please let me know if you need further assistance with any of the above.

Best wishes,
Mike
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Adrian Bennett
Top achievements
Rank 1
answered on 11 May 2009, 02:28 AM
Hi,

Thanks for your help, Ive managed to get it working properly now. I have resorted to using the stylebuilder for controls of the same type that need different themes, but there are only a few and everything else is changed using the ApplicationThemeName.

Also thanks for letting me know about the ThemeClassName, I couldnt figure out how to inherit the theme.

Cheers
Adrian
Tags
Themes and Visual Style Builder
Asked by
Adrian Bennett
Top achievements
Rank 1
Answers by
Mike
Telerik team
Adrian Bennett
Top achievements
Rank 1
Share this question
or