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