c# - Windows Phone 应用程序背景图片

标签 c# windows-phone-7

我正在尝试更改 app.xaml 中所有 xaml 页面的背景图片,但没有成功。

我正在 App 构造函数中尝试以下操作:

var imageBrush = new ImageBrush
{
    ImageSource = new BitmapImage(new Uri("/Images/SomeBackgroundImage.png", UriKind.Relative))
};

RootFrame.Background = imageBrush;

我不想在页面级别执行此操作,因为所有页面都将具有相同的背景图片,具体取决于用户选择的主题。

关于我在这里做错了什么的想法?

最佳答案

我最终做了什么:

我创建了一个方法来根据所选主题选择正确的背景图像。

public static ImageBrush GetBackground()
{
    var imageBrush = new ImageBrush();

    if ((Visibility)App.Current.Resources["PhoneLightThemeVisibility"] == Visibility.Visible)
    { 
        imageBrush = new ImageBrush
        {
            ImageSource = new BitmapImage(new Uri("/Images/Background1.png", UriKind.Relative))
        };
    }
    else
    {
        imageBrush = new ImageBrush
        {
            ImageSource = new BitmapImage(new Uri("/Images/Background2.png", UriKind.Relative))
        };
    }

    return imageBrush;
}

并且在每个页面中我都设置了背景图片。

LayoutRoot.Background = Utils.GetBackground();

关于c# - Windows Phone 应用程序背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10045848/

相关文章:

caching - 在适用于 Windows Phone 的 RestSharp 中刷新

c# - 列表框中的图像加载问题,WP7

c# - 使用 PropertyInfo.GetValue()

c# - 使用使用 NamedPipesBinding 的 WCF 服务获取 PipeException(管道正在关闭)

c# - 将 XML 结构重建为递归样式列表/XMLReader 替代方案

windows-phone-7 - 显示 WP7 应用程序的磁贴?

c# - 如何以编程方式在 WP7 中设置选定的全景项目

c# - API 的参数数组或 IEnumerable<T>

c# - WPF-C# 同步线程池线程

c# - Windows Phone 上的独立存储(IsolatedStorageSettings)限制