У меня возникла странная проблема с сортировкой WPF DataGrid (System.Windows.Controls.DataGrid в .NET 4.0).
Его ItemsSource привязан к свойству объекта datacontext:
<DataGrid HeadersVisibility="Column" SelectedIndex="0" MinHeight="30" ItemsSource="{Binding FahrtenView}" AutoGenerateColumns="False" x:Name="fahrtenDG">
ФартенВью выглядит так:
public ICollectionView FahrtenView
{
get
{
var view = CollectionViewSource.GetDefaultView(_fahrten);
view.SortDescriptions.Add(new SortDescription("Index", ListSortDirection.Ascending));
return view;
}
}
DataGrid сортируется. Однако он сортируется только в первый раз, когда ему назначается DataContext. После этого изменение DataContext (путем выбора другого «родительского» объекта в иерархии данных) по-прежнему вызывает оценку свойства FahrtenView (я могу вставить BP, и отладчик остановится на этом), но добавленное описание сортировки полностью игнорируется, поэтому сортировка не выполняется. больше не работает.
Даже вызов fahrtenDG.Items.Refresh() для каждого DataContextChange не помогает.
Я почти уверен, что это правильный путь, когда дело доходит до сортировки WPF DataGrid, не так ли? Так почему же он так упрямо отказывается работать после того, как отлично выполнил свою работу в самый первый раз, когда его вызвали?
Любая идея? Я был бы очень признателен.
Привет, Хендрик