c# - Observable collection not reacting to it's collecion -
my listbox doesn't react observablecollection.
this listbox talking about.
<listbox x:name="createfieldslist" horizontalalignment="left" height="218" verticalalignment="top" width="244" margin="0,86,0,0" borderbrush="#ffb9b9b9"> <listbox.itemtemplate> <datatemplate> <grid margin="4" width="215" height="32.96" background="white"> <textblock text="{binding name}" fontweight="normal" fontsize="18.667" padding="8,3,0,0" /> </grid> </datatemplate> </listbox.itemtemplate> </listbox>
in mainwindow, prepare data binding this
private observablecollection<fieldlistitem> _fielditems; public mainwindow() { initializecomponent(); _fielditems = new observablecollection<fieldlistitem>(); createfieldslist.itemsource = _fielditems; }
a fieldlistitem following
public class fieldlistitem : viewitem { private field _field; public string name { { return _field.name; } } public string value { { return _field.value; } } public fieldlistitem(field f) { _field = f; } }
and viewitem
public class viewitem : inotifypropertychanged { private event propertychangedeventhandler propertychanged; protected void raisepropertychanged([callermembername] string caller = "") { if (propertychanged != null) propertychanged(this, new propertychangedeventargs(caller)); } //the interface forces me implement this. why? event propertychangedeventhandler inotifypropertychanged.propertychanged { add { } remove { } } }
i don't know why isn't working. please help?
the inotifypropertychanged interface needs implement event. event implementation not work because registrations , deregistrations ignored because add , remove blocks empty.
implement event without add , remove:
public class viewitem : inotifypropertychanged { public event propertychangedeventhandler propertychanged; protected void raisepropertychanged([callermembername] string caller = "") { var copy = propertychanged; if (copy != null) copy(this, new propertychangedeventargs(caller)); } }
Comments
Post a Comment