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

[Solved] Can I set theme like this?

1 Answer 96 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Yue
Top achievements
Rank 1
Yue asked on 02 Sep 2011, 11:39 AM

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

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 02 Sep 2011, 02:55 PM
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 >>

Tags
General Discussions
Asked by
Yue
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or