How to change theme in silverlight at runtime

7 posts, 1 answers
  1. Jaroslav Půbal
    Jaroslav Půbal avatar
    52 posts
    Member since:
    Dec 2009

    Posted 21 Apr 2010 Link to this post

    I really search this forum and documentation long time and nothing found. :-(

    Is it possible in silverlight for telerik components ?
  2. Jaroslav Půbal
    Jaroslav Půbal avatar
    52 posts
    Member since:
    Dec 2009

    Posted 23 Apr 2010 Link to this post

    Is there better way for repaint complete visual tree ?
    The way described in link above is possibly destrutive to references if using "Prism regions" or MEF.

  3. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 26 Apr 2010 Link to this post

    Hello Jaroslav,

    The so called application themes replace the default styles of the controls in Generic.xaml. When you change the application theme, the controls do not update their default styles, hence you need to recreate the whole visual tree.

    Instead of setting application theme you could use the telerik:StyleManager.Theme attached property on every Telerik control (and most of the standard Silverlight controls) to specify a theme. I suppose that the best would be to provide a Theme property in your view models and bind the attached property to the Theme property - when the Theme is changed, the attached property will update all controls.

    Best wishes,
    Valeri Hristov
    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.
  4. vm0411
    vm0411 avatar
    3 posts
    Member since:
    Nov 2009

    Posted 27 Jan 2011 Link to this post

    I tried the method you described, which I nicked from the sample called "RuntimeThemeChange" somewhere on this forum.
    So it goes like :

    <TextBlock telerik:StyleManager.Theme="{Binding CurrentTheme.Theme}">My Text Box:</TextBlock>

    Works OK


    I need to add some controls (RadioButtons) in the code-behind as:

    RadioButton myRadioButton = new RadioButton();
    //need some theme binding here
    this.MyPanel.Children.Add(myRadioButton);


    How to bind the theme is this case?

  5. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 27 Jan 2011 Link to this post

    You can use something like:

    var radioButton = new RadioButton();
    radioButton.SetBinding(StyleManager.Theme, new Binding("CurrentTheme.Theme"));
    ...
    this.MyPanel.Children.Add(radioButton);

    Best wishes,
    Valeri Hristov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
  6. vm0411
    vm0411 avatar
    3 posts
    Member since:
    Nov 2009

    Posted 27 Jan 2011 Link to this post

    Thanks Valeri. Works like a charm
Back to Top