uwp - Xaml Behavior DP not updated -


i have uwp application uses managed uwp behavior sdk. wrote custom behavior has 2 dependency properties, 1 of observablecollection.

whenever update item in collection, make sure propertychanged called collection.

however, dependency property not being updated.

my code:

<trigger:custombehavior itemindex="{x:bind itemindex}"      presences="{binding elementname=box,          path=datacontext.customcollection,              updatesourcetrigger=propertychanged, converter={staticresource testconverter}}" /> 

my testconverter shows me when update item in collection, updatesource trigger working. dependency property in behavior however, not firing changed event. when change entire custom collection, dp updated, when change 1 item, isn't.

research far says dependencyobject.setvalue checks see if object has changed , if 1 item changed, think collection didn't change @ all? true, , if so, how can overcome this?

thanks

a collection-type dependency property should declared basic collection type, ienumerable. way can assign variety of actual collection types property, including implement inotifycollectionchanged, observablecollection<t>.

you check @ runtime if collection type implements interface, , possibly attach , detach handler method collectionchanged event.

public class custombehavior : ... {     public static readonly dependencyproperty presencesproperty =         dependencyproperty.register(             "presences", typeof(ienumerable), typeof(custombehavior),             new propertymetadata(null,                 (o, e) => ((custombehavior)o).onpresencespropertychanged(e)));      private void onpresencespropertychanged(dependencypropertychangedeventargs e)     {         var oldcollectionchanged = e.oldvalue inotifycollectionchanged;         var newcollectionchanged = e.newvalue inotifycollectionchanged;          if (oldcollectionchanged != null)         {             oldcollectionchanged.collectionchanged -= onpresencescollectionchanged;         }          if (newcollectionchanged != null)         {             newcollectionchanged.collectionchanged += onpresencescollectionchanged;             // in addition adding collectionchanged handler,             // existing collection elements should processed here         }     }      private void onpresencescollectionchanged(         object sender, notifycollectionchangedeventargs e)     {         // handle collection changes here     } } 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -