private static void OnListViewHeaderClick(object sender, RoutedEventArgs e) { var listView = e.Source as TreeListView.TreeList; GridViewColumnHeader header = e.OriginalSource as GridViewColumnHeader; var sortInfo = listView.GetValue(SortInfoProperty.DependencyProperty) as ResourceLibrary.Sort.SortInfo; if (sortInfo != null) { AdornerLayer.GetAdornerLayer(sortInfo.LastSortColumn).Remove(sortInfo.CurrentAdorner); listView.Items.SortDescriptions.Clear(); } else { sortInfo = new ResourceLibrary.Sort.SortInfo(); } if (sortInfo.CurrentAdorner == null) { return; } if (sortInfo.LastSortColumn == header) { (sortInfo.CurrentAdorner.Child as ResourceLibrary.Sort.SortDecorator).SortDirection = (sortInfo.CurrentAdorner.Child as ResourceLibrary.Sort.SortDecorator).SortDirection == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending; } else { sortInfo.CurrentAdorner = new ResourceLibrary.Sort.UIElementAdorner_Sort(header, new ResourceLibrary.Sort.SortDecorator()); } sortInfo.LastSortColumn = header; listView.SetValue(SortInfoProperty, sortInfo); AdornerLayer.GetAdornerLayer(header).Add(sortInfo.CurrentAdorner); SortDescription sortDescriptioin = new SortDescription() { Direction = (sortInfo.CurrentAdorner.Child as ResourceLibrary.Sort.SortDecorator).SortDirection, PropertyName = header.Column.GetValue(SortFieldProperty) as string ?? header.Column.Header as string }; listView.Items.SortDescriptions.Add(sortDescriptioin); }
internal static void SetSortInfo(DependencyObject obj, ResourceLibrary.Sort.SortInfo value) { obj.SetValue(SortInfoProperty.DependencyProperty, value); }