コード例 #1
0
 /// <summary>
 /// Synchronizes the group descriptions collection to the group descriptors collection.
 /// </summary>
 /// <param name="descriptor">The descriptor that changed</param>
 /// <param name="e">The property change event</param>
 private void HandleGroupDescriptorChanged(GroupDescriptor descriptor, PropertyChangedEventArgs e)
 {
     this._ignoreChanges = true;
     try
     {
         // We have to reset when the collections were not equal before the change
         if (this._sourceCollection.Count != this._descriptionCollection.Count)
         {
             GroupCollectionManager.ResetToGroupDescriptors(this._descriptionCollection, this._sourceCollection);
         }
         else
         {
             int index = this._sourceCollection.IndexOf(descriptor);
             GroupDescription description = GroupCollectionManager.GetDescriptionFromDescriptor(descriptor);
             if (description == null)
             {
                 this._descriptionCollection.RemoveAt(index);
             }
             else
             {
                 this._descriptionCollection[index] = description;
             }
         }
     }
     finally
     {
         this._ignoreChanges = false;
     }
 }
コード例 #2
0
 /// <summary>
 /// Resets the <paramref name="groupDescriptors"/> collection to match the <paramref name="groupDescriptions"/> collection.
 /// </summary>
 /// <param name="groupDescriptions">The collection to match</param>
 /// <param name="groupDescriptors">The collection to reset</param>
 private static void ResetToGroupDescriptions(ObservableCollection <GroupDescription> groupDescriptions, GroupDescriptorCollection groupDescriptors)
 {
     groupDescriptors.Clear();
     foreach (GroupDescription description in groupDescriptions)
     {
         groupDescriptors.Add(GroupCollectionManager.GetDescriptorFromDescription(description));
     }
 }
コード例 #3
0
 private void AssertCollectionsAreEquivalent()
 {
     if (this._sourceCollection.Count != this._descriptionCollection.Count)
     {
         // Collections may not be equivalent if a descriptor isn't fully defined
         return;
     }
     Debug.Assert(GroupCollectionManager.AreEquivalent(this._descriptionCollection, this._sourceCollection), "Collections should be equal.");
 }
コード例 #4
0
 /// <summary>
 /// Resets the <paramref name="groupDescriptions"/> collection to match the <paramref name="groupDescriptors"/> collection.
 /// </summary>
 /// <param name="groupDescriptions">The collection to reset</param>
 /// <param name="groupDescriptors">The collection to match</param>
 private static void ResetToGroupDescriptors(ObservableCollection <GroupDescription> groupDescriptions, GroupDescriptorCollection groupDescriptors)
 {
     groupDescriptions.Clear();
     foreach (GroupDescriptor descriptor in groupDescriptors)
     {
         GroupDescription description = GroupCollectionManager.GetDescriptionFromDescriptor(descriptor);
         if (description != null)
         {
             groupDescriptions.Add(description);
         }
     }
 }
コード例 #5
0
 /// <summary>
 /// Synchronizes the group descriptions collection to the group descriptors collection.
 /// </summary>
 /// <param name="e">The collection change event</param>
 private void HandleGroupDescriptorCollectionChanged(NotifyCollectionChangedEventArgs e)
 {
     this._ignoreChanges = true;
     try
     {
         // We have to reset in a number of situations
         // 1) Resetting the GroupDescriptors
         // 2) Collections were not equal before replacing GroupDescriptors
         // 3) Collections were not equal before removing GroupDescriptors
         // 4) Collections were not equal before adding GroupDescriptors
         if ((e.Action == NotifyCollectionChangedAction.Reset) ||
             ((e.Action == NotifyCollectionChangedAction.Replace) && ((this._sourceCollection.Count + e.OldItems.Count) != (this._descriptionCollection.Count + e.NewItems.Count))) ||
             ((e.Action == NotifyCollectionChangedAction.Remove) && ((this._sourceCollection.Count + e.OldItems.Count) != this._descriptionCollection.Count)) ||
             ((e.Action == NotifyCollectionChangedAction.Add) && (this._sourceCollection.Count != (this._descriptionCollection.Count + e.NewItems.Count))))
         {
             GroupCollectionManager.ResetToGroupDescriptors(this._descriptionCollection, this._sourceCollection);
         }
         else
         {
             if ((e.Action == NotifyCollectionChangedAction.Remove) ||
                 (e.Action == NotifyCollectionChangedAction.Replace))
             {
                 int index = e.OldStartingIndex;
                 if (e.Action == NotifyCollectionChangedAction.Replace) // TODO: This is a DependencyObjectCollection bug!
                 {
                     index = e.NewStartingIndex;
                 }
                 for (int i = 0; i < e.OldItems.Count; i++)
                 {
                     this._descriptionCollection.RemoveAt(index);
                 }
             }
             if ((e.Action == NotifyCollectionChangedAction.Add) ||
                 (e.Action == NotifyCollectionChangedAction.Replace))
             {
                 int index = e.NewStartingIndex;
                 foreach (object item in e.NewItems)
                 {
                     GroupDescription description = GroupCollectionManager.GetDescriptionFromDescriptor((GroupDescriptor)item);
                     if (description != null)
                     {
                         this._descriptionCollection.Insert(index++, description);
                     }
                 }
             }
         }
     }
     finally
     {
         this._ignoreChanges = false;
     }
 }
コード例 #6
0
        /// <summary>
        /// Determines whether the <paramref name="groupDescriptions"/> are equivalent to the <paramref name="groupDescriptors"/>.
        /// </summary>
        /// <param name="groupDescriptions">The descriptions to compare</param>
        /// <param name="groupDescriptors">The descriptors to compare</param>
        /// <returns><c>true</c> if the collections are equivalent</returns>
        private static bool AreEquivalent(ObservableCollection <GroupDescription> groupDescriptions, GroupDescriptorCollection groupDescriptors)
        {
            Debug.Assert((groupDescriptions != null) && (groupDescriptors != null), "Both should be non-null.");

            if (groupDescriptions.Count != groupDescriptors.Count)
            {
                return(false);
            }

            for (int i = 0, count = groupDescriptions.Count; i < count; i++)
            {
                if (!GroupCollectionManager.AreEquivalent(groupDescriptions[i], groupDescriptors[i]))
                {
                    return(false);
                }
            }

            return(true);
        }