问题描述
我想根据用户在手机上选择的主题来更改矩形的颜色.
I'm wanting to change the color of a rectangle depending on what theme the user has chosen on their phone.
EG.当用户将其设备的主题颜色设置为浅色时,矩形应为蓝色,而当主题设置为深色时,则应为灰色.
EG.When the user has their device's theme color set to light a rectangle should be blue and when the theme is set to dark it should be a grey.
有什么想法吗?
谢谢
推荐答案
我编写了一个自定义资源字典实现,该实现在运行时选择另一个字典而不会影响性能,并且可以在Visual Studio设计器中工作.您将像这样使用它:
I wrote a custom resource dictionary implementation which selects another dictionary at runtime without a performance penalty and works in the Visual Studio designer. You would use it like this:
<Application.Resources>
<custom:ThemeResourceDictionary>
<custom:ThemeResourceDictionary.LightResources>
<ResourceDictionary Source="/ThemeManagement;component/Resources/Light.xaml" />
</custom:ThemeResourceDictionary.LightResources>
<custom:ThemeResourceDictionary.DarkResources>
<ResourceDictionary Source="/ThemeManagement;component/Resources/Dark.xaml" />
</custom:ThemeResourceDictionary.DarkResources>
</custom:ThemeResourceDictionary>
</Application.Resources>
其中Light.xaml
和Dark.xaml
将包含具有相同名称的资源.
Where Light.xaml
and Dark.xaml
would contain resources with the same names.
您可以获取代码并详细了解在我的博客上.
You can get the code and read more about it on my blog.
这篇关于更改Windows Phone 7主题识别应用程序的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!