/// <summary> /// Specify a function that extracts a sortable key from object instances, that can be used to order items in the view. /// /// The ordering of the view will be checked whenever one of the items raises a property changed event /// (see <see cref="INotifyPropertyChanged"/>) for one of a set of specified properties. Only the position of the element /// raising the event will be considered. /// /// When new items are added to the collection, the function will be used to select an appropriate position /// in the view. /// </summary> /// <param name="function">The function that gets the sort key from an instance of <see cref="T"/>.</param> /// <param name="orderCheckPropertyNames">The names of the properties that should trigger a check.</param> public void OrderBy <TKey>(Func <T, TKey> function, IEnumerable <string> orderCheckPropertyNames, bool orderDescending) where TKey : IComparable { if (_mediator == null) { throw new MediatorNotSetException(); } if (_collectionOrder != null) { _collectionOrder.Detach(); } var order = new CollectionOrder <T, TKey>(function, View, _dispatcher, orderCheckPropertyNames, orderDescending); order.LoadKeysAndTriggerArrange(_target, _mediator); _collectionOrder = order; }
/// <summary> /// Specify a function that extracts a sortable key from object instances, that can be used to order items in the view. /// /// The ordering of the view will be checked whenever one of the items raises a property changed event /// (see <see cref="INotifyPropertyChanged"/>) for one of a set of specified properties. Only the position of the element /// raising the event will be considered. /// /// When new items are added to the collection, the function will be used to select an appropriate position /// in the view. /// </summary> /// <param name="function">The function that gets the sort key from an instance of <see cref="T"/>.</param> /// <param name="orderCheckPropertyNames">The names of the properties that should trigger a check.</param> /// <param name="orderDescending">True if the sort order is to be descending instead of ascending</param> public void OrderBy <TKey>(Func <TItem, TKey> function, IEnumerable <string> orderCheckPropertyNames, bool orderDescending) where TKey : IComparable { _log.LazyAdd("Set Order {0}", new Lazy <string>(function.ToString), new Lazy <string>(() => orderCheckPropertyNames.Aggregate((t, i) => t + "," + i))); if (_mediator == null) { throw new MediatorNotSetException(); } if (_collectionOrder != null) { _collectionOrder.Detach(); } var order = new CollectionOrder <TItem, TKey>(function, View, _dispatcher, orderCheckPropertyNames, orderDescending); order.LoadKeysAndTriggerArrange(View, _mediator); _collectionOrder = order; }