【问题标题】:Changing a single theme color in Windows Store 8.1 app在 Windows Store 8.1 应用程序中更改单一主题颜色
【发布时间】:2015-06-25 08:27:17
【问题描述】:

我知道 Windows Store 8.1 应用程序中只有 3 个标准主题可用。我同意。但我想为我的应用程序更改所选主题中的单一颜色或画笔(例如,我想将 Light 主题中的 ButtonBackgroundThemeBrush 更改为纯红色)。有人知道如何实现吗?

我在 SO 上发现了这些问题:

Make own windows 8 app theme

How do I mix Light and Dark themes in a C#/XAML Windows Store (Metro UI) App?

Create a theme in Windows 8.1

但我找不到任何明确的答案。

【问题讨论】:

    标签: c# xaml windows-store-apps windows-8.1


    【解决方案1】:

    如果我是你,我会在 App.cs 中设置这些颜色,可能在构造函数中,或者在加载的事件中。

    (App.Current.Resources["ButtonBackgroundThemeBrush"] as SolidColorBrush).Color = Colors.Red;
    

    据我所知,如果用户在应用打开时更改了主题,那么主题将一直存在,直到用户重新启动应用。话虽如此,您还需要考虑当前的主题。例如,如果用户使用深色主题,您不想将主题画笔设置为红色。您可以使用here概述的方法检测当前主题。

    【讨论】:

      【解决方案2】:

      好的,我找到了方法,只需将以下代码插入App.xaml即可:

      <Application.Resources>
          <ResourceDictionary>
              <ResourceDictionary.ThemeDictionaries>
                  <ResourceDictionary x:Key="Light">
                      <SolidColorBrush x:Key="ButtonBackgroundThemeBrush" Color="Red" />
                  </ResourceDictionary>
              </ResourceDictionary.ThemeDictionaries>
          </ResourceDictionary>
      </Application.Resources>
      

      【讨论】:

        猜你喜欢
        • 2019-04-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-07
        • 1970-01-01
        • 2012-03-30
        • 2016-11-01
        相关资源
        最近更新 更多