c# - WPF Binding Dependency Property to ObservableCollection -
this question has answer here:
i've got user control has dependency property:
public static readonly dependencyproperty masterlistproperty = dependencyproperty.register("masterlist", typeof(ienumerable<myobject>), typeof(mycontrol), new frameworkpropertymetadata(null, new propertychangedcallback(masterlistchanged))); my object implements inotifypropertychanged. i'm trying bind dependency property observablecollection of object. i'm not getting update when add item root collection dependency property bound to.
here's control binding dependency property collection:
<image:mycontrol masterlist="{binding path=sourcelist, updatesourcetrigger=propertychanged}"></image:mycontrol> i've tried putting mode=twoway , still don't update dependency property. have tooltip that's bound dependency property count , gets updated, masterlistchanged event isn't getting fired.
any ideas?
however i'm not getting update when add item root collection dependency property bound to.
you not supposed to. propertychangedcallback of dependency property invoked when dependency property itself set new value. won't called when add myobject source collection.
what handle collectionchanged event collection if want when item added or removed it, e.g.:
private static void masterlistchanged(dependencyobject d, dependencypropertychangedeventargs e) { var newcol = e.newvalue inotifycollectionchanged; if (newcol != null) { newcol.collectionchanged += coll_collectionchanged; } var oldcol = e.oldvalue inotifycollectionchanged; if (oldcol != null) { oldcol.collectionchanged -= coll_collectionchanged; } } private static void coll_collectionchanged(object sender, system.collections.specialized.notifycollectionchangedeventargs e) { //do something... }
Comments
Post a Comment