在C#中更改WP8应用程序背景

时间:2014-08-06 15:28:16

标签: c# windows-phone-8

我正在尝试创建一个类来添加更改我的应用壁纸的功能。这是我的班级:

namespace Wallpaper
{
    class Wallpaper
    {
        public static void SetAppBackground(string imageName)
        {
            var app = Application.Current as App;
            if (app == null)
                return;

            var imageBrush = new ImageBrush
            {
                ImageSource = new BitmapImage(new Uri(imageName, UriKind.Relative))
            };
            app.RootFrame.Background = imageBrush;
        }
    }
}

app.RootFrame.Background无法使用实例引用访问错误App.RootFrame.get;用类型名称来限定它,而不是“。”。

编辑:我想在调用函数时更改应用程序的壁纸。 imageName =图像路径。

1 个答案:

答案 0 :(得分:1)

将您的代码更改为此

public static void SetAppBackground(string imageName)
{
    var imageBrush = new ImageBrush
    {
        ImageSource = new BitmapImage(new Uri(imageName, UriKind.Relative))
    };
    App.RootFrame.Background = imageBrush;
}

但我不清楚你想做什么..

相关问题