anilbey
anilbey

Reputation: 1977

how to change background image of windows store application in c# code?

I want to change the background image of a windows store app using C#. I'm looking to change the background image similar to the following pseudo code:

This.Background.ImageSource= "dracula-128.png";

Upvotes: 0

Views: 2370

Answers (1)

keyboardP
keyboardP

Reputation: 69362

One way is to create an ImageBrush, set its ImageSource property, and then assign that to the background. (Code updated based on comment)

//BitmapImage class is within this namespace
using Windows.UI.Xaml.Media.Imaging;    

ImageBrush ib = new ImageBrush();
ib.ImageSource = new BitmapImage(new Uri(@"ms-appx:///dracula-128.png", UriKind.RelativeOrAbsolute));   
this.Background = ib;

Upvotes: 2

Related Questions