i have list of pictures in itemscontrol block shown below
<itemscontrol name="icavatars"> <itemscontrol.itemtemplate> <datatemplate> <stackpanel orientation="horizontal"> <grid> <textblock visibility="{binding ldvis}" text="loading... "/> <textblock visibility="{binding errvis}" text="error while loading image."/> <image source="{binding imgsrc}" visibility="{binding imgvis}"/> </grid> </stackpanel> </datatemplate> </itemscontrol.itemtemplate> </itemscontrol>
any time when new picture should added list, object instantiated class avatar , added list.
public class avatar { public bitmapimage imgsrc { get; set; } public visibility ldvis { get; set; } public visibility imgvis { get; set; } public visibility errvis { get; set; } } avatar avatar = new avatar(); var bitmap = new bitmapimage(new uri(uri)); bitmap.imageopened += (s, e) => avatar.showimage(); avatar.imgsrc = bitmap; icavatars.items.add(avatar);
the problem when image loaded , try change visibility property (by using avatar.imgvis), seems change on avatar object not propagated actual image. why happens?
your avatar
class should implement inotifypropertychanged
interface , each time imgvis
property changed propertychanged
event should raised. same thing should apply data bound properties can can change @ runtime.
public class avatar : inotifypropertychanged { public event propertychangedeventhandler propertychanged; private void notifypropertychanged(string propertyname) { if (propertychanged != null) { propertychanged(this, new propertychangedeventargs(propertyname)); } } private visibility _imgvis; public visibility imgvis { get{ return _imgvis; } set { if (value == _imgvis) return; _imgvis = value; notifypropertychanged("imgvis"); } } }
Comments
Post a Comment