助けになった別のスレッドを見つけました。Here で説明されているように、DataGrid.Sorting イベントを使用してデフォルトの並べ替えをオーバーライドできます。その答えは、彼または彼女が DataGrid をオーバーライドすると言っていますが、そうする必要はありません。また、データ ソースとして IList を使用したことを前提としているため、代わりに DataTable/DataView (IBindingList) ソースを前提とした例を次に示します。
private void dgPeople_Sorting(object sender, DataGridSortingEventArgs e)
{
//Assumes you've named your column colFullName in XAML
if (e.Column == colFullName)
{
ListSortDirection direction = (e.Column.SortDirection != ListSortDirection.Ascending) ? ListSortDirection.Ascending : ListSortDirection.Descending;
//set the sort order on the column
e.Column.SortDirection = direction;
//Prevent the default sorting
e.Handled = true;
//Get the static default view that the grid is bound to to redefine its sorting
BindingListCollectionView cv = (BindingListCollectionView)CollectionViewSource.GetDefaultView(dgPeople.ItemsSource);
cv.SortDescriptions.Clear();
cv.SortDescriptions.Add(new SortDescription("FirstName", direction));
cv.SortDescriptions.Add(new SortDescription("LastName", direction));
cv.Refresh();
}
}
DataView ではなく、ICollectionView (この例では BindingListCollectionView) で並べ替えを実行する必要があるという難しい方法を見つけました。そうしないと、DataView で実行する並べ替えが、ICollectionView で設定された並べ替えによって上書きされます。
このリンクは非常に役に立ちました: http://msdn.microsoft.com/en-us/library/ms752347.aspx#what_are_collection_views