change canvas image on button click in wpf -
on button click want change canvas image(background image) image in folder(images folder name). have tried:
private void button_click_2(object sender, routedeventargs e) { drawingcanvas.children.clear(); imagebrush imagebrush = new imagebrush(); imagebrush.imagesource = new bitmapimage((new uri(@"../images/canvas.png", urikind.relative))); drawingcanvas.background = imagebrush;
}
first i'm clearing contents of canvas, deleting previous image. want set background image. error: uri not handled exception. solutions appreciated. thanks.
an image resource loaded resource file pack uri:
imagebrush.imagesource = new bitmapimage( new uri("pack://application:,,,/images/canvas.png"));
in addition, build action
of image file has set resource
, shown in this answer.
Comments
Post a Comment