c# - Attach Image/ImageBrush from code behind -
i'm trying add image background of usercontrol. depending on value of variable need change background whatever path or uri format use, background not change.
i've seen lots of questions here in stackoverflow none fixes single problem. let code below:
if (callback.liveuvis.containsuvi(uvi)) { this.status.text = "live"; imagebrush imgb = new imagebrush(); bitmapimage btpimg = new bitmapimage(); btpimg.urisource = new uri(@"///img///live///bck_frame_info_video_live.png", urikind.relative); //imgb.imagesource = new bitmapimage(new uri("~/img/live/bck_frame_info_video_live.png", urikind.relativeorabsolute)); //imgb.imagesource = new bitmapimage(new uri("ms-appx:///img/live/bck_frame_info_video_live.png")); imgb.imagesource = btpimg; this.background = imgb; }
i'm facing same problem when trying attach image... guess it's uri format also, let code in case :)
private void seticon_desc(string dd) { try { image img = new image(); img.source = new bitmapimage(new uri(this.baseuri, "img/pictos_small/white/160dpi/" + dd + ".png")); img.stretch = stretch.none; this.icon = img; this.sport.text = callback.disc.getdescription(dd).toupper(); } catch(exception ex) { callback.exception.writeexceptions(ex); } }
thanks in advance!
i can reproduce issue when changing background of user control.
the current workaround used changing background of root uielement in control.
<grid x:name="container"> <grid.background> <imagebrush stretch="fill" imagesource="images/bg-blue.png"/> </grid.background> <stackpanel> <textblock>hello world</textblock> <button click="button_click">change background</button> <image x:name="display"></image> </stackpanel> </grid>
public sealed partial class myusercontrol : usercontrol { public myusercontrol() { this.initializecomponent(); } private void button_click(object sender, routedeventargs e) { imagebrush imgb = new imagebrush(); bitmapimage btpimg = new bitmapimage(); btpimg.urisource = new uri(@"ms-appx:///images/bg-light-blue.png"); imgb.imagesource = btpimg; container.background = imgb; } }
Comments
Post a Comment