How Can I use Dynamic Themes ??

6 posts, 1 answers
  1. Ahmed
    Ahmed avatar
    55 posts
    Member since:
    Oct 2012

    Posted 13 Nov 2010 Link to this post

    In My Silverlight Application which is Based in Telerik Controls ...... I want to Use Telerik Controls Themes but in Dynamic Way ....... So I want To Let User Select His Theme from Combo Box Appear in The Top of The Page and Change Telerik Controls Themes Automatic  So can U Give me A simple About How can I Handle It ??
    (Note : Beside Telerik Controls I use Also Some Silverlight Controls (Containers) : Like Grid or Stack Panel So
    1-Can I Give Telerik Themes to Silverlight Controls ?? If That is Possible so How Can I do That ?
    2-If The Pre Question is not Possible So How Can I Handle Silverlight Controls if I Give it Static Colors with Telerik Thems ?
  2. Answer
    Vanya Pavlova
    Vanya Pavlova avatar
    2019 posts

    Posted 15 Nov 2010 Link to this post

    Hello Ahmed,

    I have prepared an example for you that demonstrates how to dynamically change the theme using RadComboBox. The Telerik themes are designed to work with several Microsoft Controls, such as ListBox, TextBox, Button..... If you want to dynamically change the background of a layout container such as Grid, StackPanel, WrapPanel you should do it manually.

    Please see the attached example and if you need any further assistance let me know.
    Kind regards,
    Vanya Pavlova
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft R3 2016 release webinar banner
  4. G
    G avatar
    14 posts
    Member since:
    May 2009

    Posted 26 Nov 2010 Link to this post

    That's a nice example however you have to bind the theme to every control which looks like overkill.

    Is there anyway you can do the following (Imagine a theme has been selected from a combobox) in code behind and have it take affect?

    switch (themeName)
        case "Dark":
            StyleManager.ApplicationTheme = new Expression_DarkTheme();
        case "OfficeBlack":
            StyleManager.ApplicationTheme = new Office_BlackTheme();
        case "OfficeBlue":
            StyleManager.ApplicationTheme = new Office_BlueTheme();;

    Currently you have to restart the xap to have a new theme take affect or is there something I'm missing here? Restarting is an annoyance in a browser and impossible OOB from what I've been able to find.

  5. Vanya Pavlova
    Vanya Pavlova avatar
    2019 posts

    Posted 29 Nov 2010 Link to this post

    Hi GF,

    You can use code behind within RadComboBox's SelectionChanged event to achieve your goal, but each time you dynamically change the ApplicationTheme the view will be recreated. Having in mind this fact the preferable approach is to apply the theme using Style Manager to each control as it was demonstrated in my previous example.

    Vanya Pavlova
    the Telerik team
    Browse the videos here>> to help you get started with RadControls for Silverlight
  6. Sven J
    Sven J avatar
    26 posts
    Member since:
    Nov 2009

    Posted 23 Feb 2011 Link to this post

    I've encountered the same task - switching theme at runtime. I finally came up with this solution:
    (just insert in App.xaml.cs)

            public Theme ApplicationTheme
                get { return StyleManager.ApplicationTheme; }
                    StyleManager.ApplicationTheme = value;
                    Binding binding = new Binding("ApplicationTheme") { Source = this, Mode = BindingMode.TwoWay };
                    foreach (var element in (RootVisual as FrameworkElement).AllChildren<FrameworkElement>().ToList())
                        element.SetBinding(Telerik.Windows.Controls.StyleManager.ThemeProperty, binding);

    Extension, I used:
            public static IEnumerable<T> AllChildren<T>(this FrameworkElement ele, Func<T, bool> whereFunc = null) where T : FrameworkElement
                var c = VisualTreeHelper.GetChildrenCount(ele);
                for (var i = 0; i < c; i++)
                    var child = VisualTreeHelper.GetChild(ele, i);
                    if (child is T)
                        var childOfTypeT = child as T;

                        if (whereFunc != null && !whereFunc(childOfTypeT))

                        yield return childOfTypeT;

                        foreach (var nextchild in childOfTypeT.AllChildren<T>(whereFunc))
                            yield return nextchild;
  7. Joel Palmer
    Joel Palmer avatar
    164 posts
    Member since:
    May 2009

    Posted 06 Feb 2012 Link to this post

    Sven,  I'd like to use your approach but I can't get it working.  Is your example using Silverlight 5; Visual Studio 2010?

    I get errors on the [RootVisual as FrameworkElement).AllChildren] part of your code because AllChildren isn't an option on that item.

    Maybe I don't have your references.  Is FrameworkElement from System.Windows?

    Thanks, Joel
Back to Top
DevCraft R3 2016 release webinar banner