在Windows应用商店8.1应用中更改单个主题颜色

时间:2015-06-25 08:27:17

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

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

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

2 个答案:

答案 0 :(得分:1)

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

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

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

答案 1 :(得分:0)

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

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