c# - Changing Grid Image source on Button Click via Xaml.cs -
i new windows store application development. stuck @ trying change image of grid via c# code.
this mainpage.xaml code
<grid x:name="bg" keydown="operation" width="1327" height="740"> <grid.background> <imagebrush stretch="uniformtofill" imagesource="assets/background.jpg"/> </grid.background> <button x:name="themebutton" borderbrush="{x:null}" fontsize="14" content="theme 1" margin="25,0,0,0" horizontalalignment="left" click="changebg"></button>
this mainpage.xaml.cs code
private void changebg(object sender, routedeventargs e) { imagebrush b1 = new imagebrush(); b1.imagesource = new bitmapimage(new uri(@"d:\visual studio project file\sadiqali calculator\sadiqali calculator\assets\theme2.png")); bg.background = b1; }
when button pressed getting black background instead of picture. above code other threads.
how can change image source of grid via code on click of button?
your code works fine here when use own images.
check location of d:\visual studio project file\sadiqali calculator\sadiqali calculator\assets\theme2.png ... sure valid?
also - changebg run on ui thread if invoked button click.
Comments
Post a Comment