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 actionof image file has set resource, shown in this answer.


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -