コード例 #1
0
 /// <summary>
 /// Resets the <paramref name="sortDescriptors"/> collection to match the <paramref name="sortDescriptions"/> collection.
 /// </summary>
 /// <param name="sortDescriptions">The collection to match</param>
 /// <param name="sortDescriptors">The collection to reset</param>
 private static void ResetToSortDescriptions(SortDescriptionCollection sortDescriptions, SortDescriptorCollection sortDescriptors)
 {
     sortDescriptors.Clear();
     foreach (SortDescription description in sortDescriptions)
     {
         sortDescriptors.Add(SortCollectionManager.GetDescriptorFromDescription(description));
     }
 }
コード例 #2
0
 /// <summary>
 /// Synchronizes the sort descriptors collection to the sort descriptions collection.
 /// </summary>
 /// <param name="e">The collection change event</param>
 private void HandleSortDescriptionCollectionChanged(NotifyCollectionChangedEventArgs e)
 {
     this._ignoreChanges = true;
     try
     {
         // We have to reset in a number of situations
         // 1) Resetting the SortDescriptions
         // 2) Collections were not equal before replacing SortDescriptions
         // 3) Collections were not equal before removing SortDescriptions
         // 4) Collections were not equal before adding SortDescriptions
         if ((e.Action == NotifyCollectionChangedAction.Reset) ||
             ((e.Action == NotifyCollectionChangedAction.Replace) && ((this._sourceCollection.Count + e.NewItems.Count) != (this._descriptionCollection.Count + e.OldItems.Count))) ||
             ((e.Action == NotifyCollectionChangedAction.Remove) && (this._sourceCollection.Count != (this._descriptionCollection.Count + e.OldItems.Count))) ||
             ((e.Action == NotifyCollectionChangedAction.Add) && ((this._sourceCollection.Count + e.NewItems.Count) != this._descriptionCollection.Count)))
         {
             SortCollectionManager.ResetToSortDescriptions(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 ObservableCollection bug!
                 {
                     index = e.NewStartingIndex;
                 }
                 for (int i = 0; i < e.OldItems.Count; i++)
                 {
                     this._sourceCollection.RemoveAt(index);
                 }
             }
             if ((e.Action == NotifyCollectionChangedAction.Add) ||
                 (e.Action == NotifyCollectionChangedAction.Replace))
             {
                 int index = e.NewStartingIndex;
                 foreach (object item in e.NewItems)
                 {
                     this._sourceCollection.Insert(index++, SortCollectionManager.GetDescriptorFromDescription((SortDescription)item));
                 }
             }
         }
     }
     finally
     {
         this._ignoreChanges = false;
     }
 }