Setting or modifying ThemeResource in code

后端 未结 5 724
野趣味
野趣味 2021-02-06 04:14

My questions is very specific to ThemeResources in a Windows 10 Store App. Unfortunately several things available in \"classic\" WPF are different or not available here.

5条回答
  •  离开以前
    2021-02-06 04:49

    I'm using this to set newAccentColor, until I can find a way to do it without toggling the theme. This updates all the derived brushes based on accent color:

    Application.Current.Resources["SystemAccentColor"] = newAccentColor;
    if (Window.Current.Content is FrameworkElement fe)
    {
          var requestedTheme = fe.RequestedTheme;
          fe.RequestedTheme = fe.RequestedTheme == ElementTheme.Light ? ElementTheme.Dark : ElementTheme.Light;
          fe.RequestedTheme = requestedTheme;
    }
    

提交回复
热议问题