} /* method ListViewSorter OnIsSortableChanged */ /// <summary> /// Sorts the ListView on the given column /// </summary> /// <param name="columnHeader"></param> /// <param name="listView"></param> /// <remarks> /// The data will be sorted by suppling a SortDescription. The property name for the /// sort will come from one of three places in order /// 1) - Explicitly specfied name (SortPropertyName attached property) /// 2) - A XPath specification in the column binding /// 3) - The Path property from the binding Path /// </remarks> static public void SortByColumn(GridViewColumnHeader columnHeader, ListView listView) { GridViewColumnHeader last_sorted_header; ListSortDirection sort_direction; SortDirectionAdorner adorner; string sort_property_name; Binding binding; if (columnHeader.Column != null) // user clicked a valid column header { /* * Determine the sort property name * If we cannot determine it, do nothing * */ if ((sort_property_name = GetSortPropertyName(columnHeader)) == null) { /* * Binding is not present if a CellTemplate is used * */ if ((binding = ((Binding)columnHeader.Column.DisplayMemberBinding)) == null) { goto function_exit; } sort_property_name = binding.XPath; if (string.IsNullOrEmpty(sort_property_name)) { sort_property_name = ((Binding)columnHeader.Column.DisplayMemberBinding).Path.Path; } } last_sorted_header = GetLastColumnSorted(listView); if (last_sorted_header != null) { AdornerLayer.GetAdornerLayer(last_sorted_header).Remove(GetAdorner(last_sorted_header)); } sort_direction = ((GetLastSortDirection(columnHeader) == ListSortDirection.Ascending) ? ListSortDirection.Descending : ListSortDirection.Ascending); SetLastSortDirection(columnHeader, sort_direction); SetLastColumnSorted(listView, columnHeader); listView.Items.SortDescriptions.Clear(); listView.Items.SortDescriptions.Add(new SortDescription(sort_property_name, sort_direction)); adorner = new SortDirectionAdorner(columnHeader, sort_direction); SetAdorner(columnHeader, adorner); AdornerLayer.GetAdornerLayer(columnHeader).Add(adorner); } function_exit: ; } /* method ListViewSorter SortByColumn */
/// <summary> /// Sorts the ListView on the given column /// </summary> /// <param name="columnHeader"></param> /// <param name="listView"></param> /// <remarks> /// The data will be sorted by suppling a SortDescription. The property name for the /// sort will come from one of three places in order /// 1) - Explicitly specfied name (SortPropertyName attached property) /// 2) - A XPath specification in the column binding /// 3) - The Path property from the binding Path /// </remarks> public static void SortByColumn(GridViewColumnHeader columnHeader, ListView listView) { GridViewColumnHeader last_sorted_header; ListSortDirection sort_direction; SortDirectionAdorner adorner; string sort_property_name; Binding binding; if (columnHeader.Column != null) // user clicked a valid column header { /* * Determine the sort property name * If we cannot determine it, do nothing * */ if ((sort_property_name = GetSortPropertyName(columnHeader)) == null) { /* * Binding is not present if a CellTemplate is used * */ if ((binding = ((Binding)columnHeader.Column.DisplayMemberBinding)) == null) goto function_exit; sort_property_name = binding.XPath; if (string.IsNullOrEmpty(sort_property_name)) sort_property_name = ((Binding)columnHeader.Column.DisplayMemberBinding).Path.Path; } last_sorted_header = GetLastColumnSorted(listView); if (last_sorted_header != null) AdornerLayer.GetAdornerLayer(last_sorted_header).Remove(GetAdorner(last_sorted_header)); sort_direction = ((GetLastSortDirection(columnHeader) == ListSortDirection.Ascending) ? ListSortDirection.Descending : ListSortDirection.Ascending); SetLastSortDirection(columnHeader, sort_direction); SetLastColumnSorted(listView, columnHeader); listView.Items.SortDescriptions.Clear(); listView.Items.SortDescriptions.Add(new SortDescription(sort_property_name, sort_direction)); adorner = new SortDirectionAdorner(columnHeader, sort_direction); SetAdorner(columnHeader, adorner); AdornerLayer.GetAdornerLayer(columnHeader).Add(adorner); } function_exit: ; }