Beispiel #1
0
        /// <summary>
        /// Sorts the list based on a <see cref="T:System.ComponentModel.PropertyDescriptor"/> and a <see cref="T:System.ComponentModel.ListSortDirection"/>.
        /// </summary>
        /// <param name="property">The <see cref="T:System.ComponentModel.PropertyDescriptor"/> to sort by.</param>
        /// <param name="direction">One of the <see cref="T:System.ComponentModel.ListSortDirection"/> values.</param>
        /// <exception cref="T:System.NotSupportedException">
        ///     <see cref="P:System.ComponentModel.IBindingList.SupportsSorting"/> is false. </exception>
        public void ApplySort(PropertyDescriptor property, ListSortDirection direction)
        {
            if (property == _sortProperty && direction == _sortDirection)
            {
                return;
            }

            if (IsSorted)
            {
                UnwireInterceptor();
            }

            _sortProperty  = property;
            _sortDirection = direction;

            Expression <Func <TElement, object> > selector = item => KeySelector(item);

            var q = ListSortDirection.Ascending == _sortDirection?_originalSource.OrderBy(selector) : _originalSource.OrderByDescending(selector);

            WireInterceptor(q.DependsOn(_sortProperty.Name));

            OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
        }
Beispiel #2
0
 /// <summary>
 /// Sorts the elements of a sequence in ascending order according to a key.
 /// </summary>
 /// <typeparam name="TSource">The type of the elements of <paramref name="source"/>.</typeparam>
 /// <typeparam name="TKey">The type of the key returned by <paramref name="keySelector"/>.</typeparam>
 /// <param name="source">A sequence of values to order.</param>
 /// <param name="keySelector">A function to extract a key from an element.</param>
 /// <param name="dependencyAnalysisMode">The dependency analysis mode.</param>
 /// <returns>
 /// An <see cref="T:System.Linq.IOrderedEnumerable`1"/> whose elements are sorted according to a key.
 /// </returns>
 /// <exception cref="T:System.ArgumentNullException">
 ///     <paramref name="source"/> or <paramref name="keySelector"/> is null.</exception>
 public static IOrderedBindableCollection <TSource> OrderBy <TSource, TKey>(this IBindableCollection <TSource> source, Expression <Func <TSource, TKey> > keySelector, DependencyDiscovery dependencyAnalysisMode) where TSource : class
 {
     return(source.OrderBy(keySelector, null, dependencyAnalysisMode));
 }