c# - Notified of property change of an Item within a Collection -


at moment have collection of users. use collection populate itemscontrol datatemplate of checkboxes. populate first item select all

analysts.add(new userdto {     id         = 0,     name       = "select all",     isselected = true }); 

i'm wondering how create event such if of checkboxes ticked, event fired. tried set analysts.collectionchanged += analysts_collectionchanged; wouldn't fire unless collection literally changed, not item properties.

usersdto.cs

public int id {get; set;} private string _name; public string name {     { return _name; }     set {_name = value; onpropertychanged("name");} }  private bool _isselected; public bool isselected {     { return _isselected; }     set { _isselected = value; onpropertychanged("isselected"); } } 

dismissappointmentview

<itemscontrol grid.column="1" grid.row="1" itemssource="{binding analysts, updatesourcetrigger=propertychanged}" istabstop="false">     <itemscontrol.itemspanel>         <itemspaneltemplate>             <telerik:raduniformgrid rows="2"/>         </itemspaneltemplate>     </itemscontrol.itemspanel>     <itemscontrol.itemtemplate>         <datatemplate>             <checkbox telerik:stylemanager.theme="windows8" margin="3 3 12 3" content="{binding name}" ischecked="{binding isselected, mode=twoway}"/>         </datatemplate>     </itemscontrol.itemtemplate> </itemscontrol> 

you might want use this:

 public class observablecollectionex<t> : observablecollection<t> t : inotifypropertychanged     {         public observablecollectionex() : base() { }          public observablecollectionex(list<t> list)             : base((list != null) ? new list<t>(list.count) : list)         {             copyfrom(list);         }          public observablecollectionex(ienumerable<t> collection)         {             if (collection == null)                 throw new argumentnullexception("collection");             copyfrom(collection);         }          private void copyfrom(ienumerable<t> collection)         {             ilist<t> items = items;             if (collection != null && items != null)             {                 using (ienumerator<t> enumerator = collection.getenumerator())                 {                     while (enumerator.movenext())                     {                         items.add(enumerator.current);                     }                 }             }         }          protected override void insertitem(int index, t item)         {             base.insertitem(index, item);             item.propertychanged += item_propertychanged;         }          protected override void removeitem(int index)         {             items[index].propertychanged -= item_propertychanged;             base.removeitem(index);         }          protected virtual void moveitem(int oldindex, int newindex)         {             t removeditem = this[oldindex];             base.removeitem(oldindex);             base.insertitem(newindex, removeditem);         }          protected override void clearitems()         {             foreach (t item in items)             {                 item.propertychanged -= item_propertychanged;             }             base.clearitems();         }          protected override void setitem(int index, t item)         {             t olditem = items[index];             t newitem = item;             olditem.propertychanged -= item_propertychanged;             newitem.propertychanged += item_propertychanged;             base.setitem(index, item);         }          private void item_propertychanged(object sender, propertychangedeventargs e)         {             var handler = itempropertychanged;             if (handler != null) { handler(sender, e); }         }          public event propertychangedeventhandler itempropertychanged;     } 

now can subscribe propertychanged-event of elements in collection


Comments