JohnSmith
JohnSmith

Reputation: 59

Set Background to canvas

how i can set background on string path?

canvas1.Background = "/path/";

please help!!! thanks :)

Upvotes: 1

Views: 6550

Answers (2)

Nikhil Agrawal
Nikhil Agrawal

Reputation: 48558

Use this

mycanvas.Background = new ImageBrush() 
          { ImageSource = new BitmapImage((new Uri(mypath, UriKind.Absolute))) };

Upvotes: 1

nemesv
nemesv

Reputation: 139748

I think you are looking for the ImageBrush class:

ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = new BitmapImage(new Uri(@"/path/", UriKind.Relative));
canvas1.Background = imageBrush;

Upvotes: 3

Related Questions