Loading multiple themes for similar controls

3 posts, 1 answers
  1. Adrian Bennett
    Adrian Bennett avatar
    5 posts
    Member since:
    Mar 2009

    Posted 08 May 2009 Link to this post


    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(...);


    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

  2. Answer
    Mike avatar
    640 posts

    Posted 08 May 2009 Link to this post

    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:

    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 
            return typeof(RadPanel).FullName; 
            //nothing to do in this case

    Please, take a look at the following KB article for details:

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

    Best wishes,
    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.
  3. DevCraft R3 2016 release webinar banner
  4. Adrian Bennett
    Adrian Bennett avatar
    5 posts
    Member since:
    Mar 2009

    Posted 10 May 2009 Link to this post


    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.

Back to Top