WP7项目中的主题感知XAML资源

San*_*ock 3 xaml windows-phone-7

我正在制作一个Windows Phone 7应用程序,我对暗/亮主题有点困惑.

使用全景图时,您经常会设置背景图像.问题在于制作适合黑暗和光明主题的照片非常困难.我们该怎么办?

有没有办法强制全景的暗/亮主题?这将避免制作特定主题的全景背景图片.那怎么办?我找到了xaml文件C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Design.如果这是一种正确的方法,我怎样才能导入我的全景图?

或者,如果没有办法(或者如果它是错的)强制暗/亮主题:如何编写条件XAML来设置正确的资源?现在我有以下XAML(default.xaml),黑暗主题很好:

<ImageBrush x:Key="PageBackground" ImageSource="Resources/PageBackground.png" Stretch="None" />
<ImageBrush x:Key="PanoramaBackground" ImageSource="Resources/PanoramaBackground.png" Stretch="None" />
Run Code Online (Sandbox Code Playgroud)

但是当我使用浅色主题时,黑色背景图片难以阅读黑色控件和黑色文本.所以我制作了不同的图片,我可以用这种方式:

<ImageBrush x:Key="PageBackground" ImageSource="Resources/PageBackgroundLight.png" Stretch="None" />
<ImageBrush x:Key="PanoramaBackground" ImageSource="Resources/PanoramaBackgroundLight.png" Stretch="None" />
Run Code Online (Sandbox Code Playgroud)

现在我的问题是让XAML有条件地根据当前主题声明正确的东西.

我在互联网上找不到相关的方法.我宁愿不使用代码或代码隐藏,因为我相信XAML能够做到这一点(我只是不知道如何).

编辑:用于将xaml文件加载为ResourceDictionary的代码片段

string xaml = null;
StreamResourceInfo xamlInfo = Application.GetResourceStream(new Uri("light.xaml", UriKind.Relative));
using (StreamReader sr = new StreamReader(xamlInfo.Stream))
    xaml = sr.ReadToEnd();
dic = (ResourceDictionary)XamlReader.Load(xaml);
this.Resources.MergedDictionaries.Add(dic);
Run Code Online (Sandbox Code Playgroud)

You*_*sef 5

要强制使用黑色或白色主题,您确实可以使用您指出的文件夹中定义的样式.将您需要的规则复制并粘贴到App.xaml(只需PhoneForegroundColor,PhoneBackgroundColor和相关的Brushes就是一个好的开始).

尽管保持"主题感知"并为明暗主题加载不同的图像可能会更好.这是一篇解释如何执行此操作的文章:http://blog.jayway.com/2010/12/16/theme-aware-panorama-background-in-windows-phone-7/