/// <summary> /// Synchronizes the sort descriptions collection to the sort descriptors collection. /// </summary> /// <param name="descriptor">The descriptor that changed</param> /// <param name="e">The property change event</param> private void HandleSortDescriptorChanged(SortDescriptor 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) { SortCollectionManager.ResetToSortDescriptors(this._descriptionCollection, this._sourceCollection); } else { int index = this._sourceCollection.IndexOf(descriptor); SortDescription? description = SortCollectionManager.GetDescriptionFromDescriptor(descriptor); if (!description.HasValue) { this._descriptionCollection.RemoveAt(index); } else { this._descriptionCollection[index] = description.Value; } } } finally { this._ignoreChanges = false; } }
/// <summary> /// Determines whether the <paramref name="sortDescription"/> and <paramref name="sortDescriptor"/> are equivalent. /// </summary> /// <param name="sortDescription">The description to compare</param> /// <param name="sortDescriptor">The descriptor to compare</param> /// <returns><c>true</c> if the two are equivalent</returns> private static bool AreEquivalent(SortDescription sortDescription, SortDescriptor sortDescriptor) { Debug.Assert((sortDescription != null) && (sortDescriptor != null), "Both should be non-null."); return (sortDescription.Direction == sortDescriptor.Direction) && (sortDescription.PropertyName == sortDescriptor.PropertyPath); }
/// <summary> /// Returns a <see cref="SortDescription"/> equivalent to the specified descriptor. /// </summary> /// <param name="sortDescriptor">The descriptor to get a description from</param> /// <returns>A <see cref="SortDescription"/> equivalent to the specified descriptor</returns> private static SortDescription? GetDescriptionFromDescriptor(SortDescriptor sortDescriptor) { if (string.IsNullOrEmpty(sortDescriptor.PropertyPath)) { return null; } return new SortDescription(sortDescriptor.PropertyPath, sortDescriptor.Direction); }