更改 Windows Store 8.1 应用中的单个主题颜色

Changing a single theme color in Windows Store 8.1 app

我知道 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

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

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

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

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

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

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