/// <summary> /// Custom sort the datagrid since the actual records are stored in the /// server, not in the items collection of the datagrid. /// </summary> /// <param name="sender">The parts data grid.</param> /// <param name="e">Contains the column to be sorted.</param> private void AssessmentsDataGrid_Sorting(object sender, DataGridSortingEventArgs e) { e.Handled = true; DashboardModel mainViewModel = (DashboardModel)DataContext; string sortField = String.Empty; // Use a switch statement to check the SortMemberPath // and set the sort column to the actual column name. In this case, // the SortMemberPath and column names match. switch (e.Column.SortMemberPath) { case ("Organisation"): sortField = "Organisation"; break; case ("Title"): sortField = "Title"; break; case ("ReportGenerationDate"): sortField = "ReportGenerationDate"; break; case ("CreatedDate"): sortField = "CreatedDate"; break; } ListSortDirection direction = (e.Column.SortDirection != ListSortDirection.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending; bool sortAscending = direction == ListSortDirection.Ascending; mainViewModel.Sort(sortField, sortAscending); currentSortColumn.SortDirection = null; e.Column.SortDirection = direction; currentSortColumn = e.Column; currentSortDirection = direction; }