Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set background of a stackpanel to an image in c#

I need to set the Background of a Stackpanel to some image in the resources.
I know that i should set the background as follows:

Stack.Background= image; // don't know of what type the image should be how to set it   

Any help is appreciated,

like image 800
Ameen Avatar asked Jan 18 '26 14:01

Ameen


2 Answers

string fileName = "/Background.png";
BitmapImage image = new BitmapImage(new Uri(fileName, UriKind.Relative));
ImageBrush brush = new ImageBrush();
brush.ImageSource = image;
stack.Background = brush;
like image 96
Rich Hopkins Avatar answered Jan 21 '26 08:01

Rich Hopkins


StackPanel.Background is of type Brush, and you'll need to create an ImageBrush in order to display an image on the StackPanel.

like image 39
ajmccall Avatar answered Jan 21 '26 07:01

ajmccall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!