/// <summary>
 /// Called whenever one of the inner collection changed.
 /// </summary>
 /// <param name="managerType">Type of the manager we subscribed to.</param>
 /// <param name="sender">The collection that sent the event.</param>
 /// <param name="e">Information about the event.</param>
 /// <returns>True if was able to perform the required operation.</returns>
 /// <remarks><see cref="IWeakEventListener"/> implementation.</remarks>
 public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
 {
     if (TargetObject != null && TargetProperty != null)
     {
         if (managerType == typeof(CollectionChangedEventManager))
         {
             // Update only if collection change event args matches the allowed actions for notification:
             if (e is NotifyCollectionChangedEventArgs collectionargs && ActionsToNotify.HasFlag(collectionargs.Action))
             {
                 // Update binding target when collection changed:
                 if (updateTargetAction != null)
                 {
                     if (Application.Current.Dispatcher.CheckAccess())
                     {
                         updateTargetAction.Invoke();
                     }
                     else
                     {
                         Application.Current.Dispatcher.BeginInvoke(updateTargetAction);
                     }
                 }
             }
         }
     }
     else if (sender is INotifyCollectionChanged collection)
     {
         CollectionChangedEventManager.RemoveListener(collection, this); // our binding expression is not used anymore, we can shut listening down.
     }
     return(true);                                                       // always return true otherwise ugly exception happen in the framework core.
 }
示例#2
0
 /// <summary>
 /// Called whenever one of the inner collection changed.
 /// </summary>
 /// <param name="managerType">Type of the manager we subscribed to.</param>
 /// <param name="sender">The collection that sent the event.</param>
 /// <param name="e">Information about the event.</param>
 /// <returns>True if was able to perform the required operation.</returns>
 /// <remarks><see cref="IWeakEventListener"/> implementation.</remarks>
 public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
 {
     if (IsExtensionValid)
     {
         if (managerType == typeof(CollectionChangedEventManager))
         {
             // Update only if collection change event args matches the allowed actions for notification:
             if (e is NotifyCollectionChangedEventArgs collectionargs && ActionsToNotify.HasFlag(collectionargs.Action))
             {
                 // Update binding target when collection changed:
                 (GeneratedMultibindingExpression.Target as MultiBindingExpression).UpdateTarget();
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }