c# - Crash on changing the Image source property -


<image x:name="pageimg" margin="-19,-1,37,19" source="/img/1.png" stretch="uniform"  /> 

the images property set build action = resource , copy output directory = cope if newer

when button clicked application crashes:

    private void button_click_1(object sender, routedeventargs e)     {             pageimg.source = new bitmapimage(new uri(@"/img/2.png"));         } 

but when pass c:\users\myuser\desktop\2.png instead of /img/2.png works fine.

why happening?

an image resource file (with build action set resource) should loaded resource file pack uri:

pageimg.source = new bitmapimage(new uri("pack://application:,,,/img/2.png")); 

it not necessary copied output directory.


Comments