Reputation: 79
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
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