Afterlife
Afterlife

Reputation: 79

Change WP8 App Background in C#

I am trying to create a class to add the ability to change the wallpaper of my app. This is my class:

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;
        }
    }
}

But app.RootFrame.Background gives an error App.RootFrame.get cannot be accessed with an instance reference; qualify it with a type name instead"`.

EDIT: I want to change the wallpaper of my application when I call the function. imageName = image path.

Upvotes: 1

Views: 95

Answers (1)

Kasun Kodagoda
Kasun Kodagoda

Reputation: 4024

Change your code to this

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

But im not clear what are you trying to do..

Upvotes: 1

Related Questions