xaml - wpf binding list inside class not updating -
when want bind observablecollection of strings ui. this:
observablecollection<string> mystrings = new observablecollection<string>(); mystrings.add("hello"); myitemscontrol.itemssource = mystrings;
then when add/remove elements list, ui updates.
however, when add observablecollection class binding not update:
public class testclass { public observablecollection<string> mystrings = new observablecollection<string>(); } testclass mytestclass = new testclass(); mytestclass.mystrings.add("hello"); myitemscontrol.itemssource = mytestclass.mystrings;
the binding works first time not update when add/remove items. can explain me why happens , how can around it?
you're trying bind field, not property. change class
public class testclass { public testclass() { mystring = new observablecollection<string>(); } public observablecollection<string> mystrings {get; set;} }
and should work expected.
Comments
Post a Comment