Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1130
Setting theme at runtime?
posted

Hi,

 I'm trying to set a theme at runtime, but I see no changes in my UI.  Here's what I'm trying.

                 switch ( theme ) {
                    case 1:
                        ThemeManager.CurrentTheme = ThemeManager.ThemeNameAero;
                        break;
                    case 2:
                        ThemeManager.CurrentTheme = ThemeManager.ThemeNameLeaf;
                        break;
                    case 3:
                        ThemeManager.CurrentTheme = ThemeManager.ThemeNameOnyx;
                        break;
                    case 4:
                        ThemeManager.CurrentTheme = ThemeManager.ThemeNameOffice2k7Silver;
                        break;
                    default:
                        throw new Exception();
                }

 

But it doesn't seem to work.  I've also tried getting the PrimativesXXX ResourceDictionary merged into the apps ResourceDictionary, but that doesn't work either.

The above code is in the App.xaml.cs.

Thanks

Andy

Parents
  • 69686
    posted

     Hello Andy,

    I have managed changing the current theme by creating a Style targeting the element you want to change the theme of. For example, I want to change the current theme of my XamDataGrid and I do the following:

    string[ themes = ThemeManager.GetThemes();

    Style myStyle = new Style();
    myStyle.TargetType = typeof(XamDataGrid);
    myStyle.Setters.Add(new Setter(XamDataGrid.ThemeProperty,themes[0]));
    xamDataGrid.Style = myStyle ;

    Does this work in your case? 

Reply Children