/// <summary> /// A header was clicked. Sort the associated column. /// </summary> private void OnHeaderClicked(object sender, RoutedEventArgs e) { // Make sure the column is really being sorted. GridViewColumnHeader header = e.OriginalSource as GridViewColumnHeader; if (header == null || header.Role == GridViewColumnHeaderRole.Padding) return; SortListViewColumn column = header.Column as SortListViewColumn; if (column == null) return; // See if a new column was clicked, or the same column was clicked. if (sortColumn != column) { // A new column was clicked. previousSortColumn = sortColumn; sortColumn = column; sortDirection = ListSortDirection.Ascending; } else { // The same column was clicked, change the sort order. previousSortColumn = null; sortDirection = (sortDirection == ListSortDirection.Ascending) ? ListSortDirection.Descending : ListSortDirection.Ascending; } // Sort the data. SortList(column.SortProperty); // Update the column header based on the sort column and order. UpdateHeaderTemplate(); }
/// <summary> /// Sets the column width based on the length of the title. /// Required for localization. /// </summary> /// <param name="menu"></param> /// <param name="columnName"></param> /// <returns></returns> private static double CalculateColumnWidth(MenuItem menu, SortListViewColumn columnName) { if (menu.IsChecked && columnName.Header != null) { string s = columnName.Header.ToString(); int i = s.Length; int ii = 8; columnName.Width = (i * ii) + 25; return(columnName.Width); } else if (menu.IsChecked && columnName.Header == null) { columnName.Width = 24; return(24); } else { columnName.Width = 0; return(0); } }
/// <summary> /// A header was clicked. Sort the associated column. /// </summary> private void OnHeaderClicked(object sender, RoutedEventArgs e) { // Make sure the column is really being sorted. GridViewColumnHeader header = e.OriginalSource as GridViewColumnHeader; if (header == null || header.Role == GridViewColumnHeaderRole.Padding) { return; } SortListViewColumn column = header.Column as SortListViewColumn; if (column == null) { return; } // See if a new column was clicked, or the same column was clicked. if (sortColumn != column) { // A new column was clicked. previousSortColumn = sortColumn; sortColumn = column; sortDirection = ListSortDirection.Ascending; } else { // The same column was clicked, change the sort order. previousSortColumn = null; sortDirection = (sortDirection == ListSortDirection.Ascending) ? ListSortDirection.Descending : ListSortDirection.Ascending; } // Sort the data. SortList(column.SortProperty); // Update the column header based on the sort column and order. UpdateHeaderTemplate(); }