xamarin.ios - Updating a ListView with Xamarin.Forms -
i having issue list views on in couple of xamarin forms applications. 1 form within tabbed page setup, other normal content page (different apps)
i have class this
public class someclass { public string stringone {get;set;} public string stringtwo {get;set;} public int intone {get;set;} }
in content page, set observablecollection , add data in. tell list someclass itemsource. produces listview correctly on of devices.
the problem when change 1 of properties, nothing on listview changes (so if have 3 objects in observable , remove one, list still says 3 - or if change property in second object, second item on listview doesn't change either).
i have tried solve problem using standard list , implement inotifychanged within class. again though, listview doesn't alter when list changes.
i know data has altered if make change object, come out , go in, data has changed in ui.
am doing wrong or bug need putting bugzilla?
it not change if don't bind , implement inotifypropertychanged
interface.
sample code:
public class observableproperty : inotifypropertychanged { public event propertychangedeventhandler propertychanged; protected void onpropertychanged(string propertyname) { var handler = propertychanged; if (handler != null) handler(this, new propertychangedeventargs(propertyname)); } } public class someclass:observableproperty { string stringone; string stringtwo; int intone; public string stringone { get{return stringone;} set { stringone = value; onpropertychanged("stringone"); } } public string stringtwo { get{ return stringtwo;} set { stringtwo = value; onpropertychanged("stringtwo"); } } public int intone { get{ return intone;} set { intone = value; onpropertychanged("intone"); } } } public class mainvm:observableproperty { observablecollection<someclass> items; public observablecollection<someclass> items { get{return items;} set { items = value; onpropertychanged("items"); } } public mainvm() { items = new observablecollection<someclass>(); items.add(new someclass(){stringone = "123", stringtwo = "test", intone =12}); } public void callmeforchangingproperty() { someclass item = items[0]; item.stringone = "test1"; } } public class mainview { public mainview() { this.bindingcontext= new mainvm() } } < listview itemssource="{binding items}" rowheight="120"> < listview.itemtemplate> < datatemplate> < viewcell> < viewcell.view> < stacklayout> < label text= "stringone" /> < label text= "stringtwo" /> < label text= "intone" /> </ stacklayout> </ viewcell.view> </ viewcell> </ datatemplate> </ listview.itemtemplate> </ listview>
Comments
Post a Comment