Can I set theme like this?

2 posts, 0 answers
  1. Yue
    Yue avatar
    16 posts
    Member since:
    Aug 2011

    Posted 02 Sep 2011 Link to this post

    I have created a RadComboBox to select Theme.

    <telerik:RadComboBox Width="100" Height="30"  Margin="20,5" VerticalAlignment="Bottom" SelectionChanged="RadComboBox_SelectionChanged">
         <telerik:RadComboBoxItem Content="Expression_Dark" />
         <telerik:RadComboBoxItem Content="Office_Black" />              
         <telerik:RadComboBoxItem Content="Office_Blue" />
         <telerik:RadComboBoxItem Content="Office_Silver" />
         <telerik:RadComboBoxItem Content="Summer" />
         <telerik:RadComboBoxItem Content="Transparent" />
         <telerik:RadComboBoxItem Content="Vista" />
         <telerik:RadComboBoxItem Content="Windows7" />
     </telerik:RadComboBox>

    And my code in MainPage.xaml.cs:

    public MainPage()
     
    {
     
     StyleManager.ApplicationTheme = new Windows7Theme();
     
    InitializeComponent();
     
    }
     
    private MainPage(int index) //overload of Mainpage()
     
    {
     
     switch (index)
     
     {
     
     case 0: StyleManager.ApplicationTheme = new Expression_DarkTheme(); break;
     
     case 1: StyleManager.ApplicationTheme = new Office_BlackTheme(); break;
     
     case 2: StyleManager.ApplicationTheme = new Office_BlueTheme(); break;
     
     case 3: StyleManager.ApplicationTheme = new Office_SilverTheme(); break;
     
     case 4: StyleManager.ApplicationTheme = new SummerTheme(); break;
     
     case 5: StyleManager.ApplicationTheme = new TransparentTheme(); break;
     
     case 6: StyleManager.ApplicationTheme = new VistaTheme(); break;
     
     case 7: StyleManager.ApplicationTheme = new Windows7Theme(); break;
     
    }
     
     InitializeComponent();
     
    }
     
    private void RadComboBox_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
     
    {
     
     RadComboBox comboBox = sender as RadComboBox;
     
     int index = comboBox.SelectedIndex;
     
     this.RootVisual = new MainPage(index);
     
    }

    But it seems that this could not work right.
    So, what's wrong with my code? And what's the right way to set theme at runtime?

    Thanks, any help will be appreciated.

    Yue

  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 02 Sep 2011 Link to this post

    Hi Yue,

    Changing themes this way will not help. After setting a new theme runtime  , the visual tree needs to be reloaded in order changes to take effect. For example you may place your controls in a ContentControl. After changing the theme - reload the content.

    All the best,
    Pavel Pavlov
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top