Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
XamDataGrid Sorting and Grouping ICollectionView using MVVM
posted

I'm binding a XamDataGrid DataSource to the ICollectionView of an ObservableCollection in my ViewModel. When I remove the CurrentItem of the ICollectionView from the ObservableCollection in the ViewModel, I would like the CurrentItem to select the next object in the ObservableCollection as it appears to the user. If the user performs sorting or grouping on the XamDataGrid, the selection appears to jump around randomly when I remove the CurrentItem from the ObservableCollection, because the "next" item of the ObservableCollection corresponds to the order in which the objects were added to the ObservableCollection, not the order the objects are rendered on the screen inside the XamDataGrid (because of sorting and / or grouping).

I've tried subscribing to my XamDataGrid's Sorting and Grouping events, and populating the ICollectionView's SortDescriptions and GroupDescriptions properties in the event handlers, which seems to synchronize the XamDataGrid with the ObservableCollection, but this seems like it shouldn't be necessary.

Is the XamDataGrid capable of populating my ICollectionView SortDescriptions and GroupDescriptions properties directly, without the need for subscribing to these events? Is there another way of "synchronizing" the order of objects in my ObservableCollection?