Hello.
I have a XamGrid with available grouping column. And AutoGeneratedColumns is false. ItemsSource binding on ViewModel's property.
I do next:
1. group XamGrid on some column.
2. change DataContext of XamGrid to null and then change DataContext on some other ViewModel. I expect that ItemsSource of XamGrid is changed and sorting and grouping options will not change.
But after changing DataContext there is no any grouped columns on XamGrid.
There is a bug? There is any workaround when grouping settings are not reset?
BR
Alexey Lukyanov
If you want to maintain the sort and grouping, you can use the persistence framework to save the layout of the grid to a memory stream, reset your data context, and then restore the sorting and grouping.
When the .DataContext is cleared (or the ItemSource) the groupby / sorting settings are removed by design.
Thanks for fast response.
You do not plan to add that feature in future? I think it is not very good use so resource-intensive persistence framework for this simple task.
BR,
To elaborate on what Darrell mentioned, basically once you clear the ItemsSource of the xamGrid, we have to assume that data is changing, and we need to forget where we are.
If you were to set the ItemsSource with out setting it to null, we would keep the state, assuming the underlying data type of the collection doesn't change. (although as you reported there is a memory leak here that will be addressed in the next SR).
Basically, if we don't do this, we wind up upsetting customers that expected it being cleared, so we wind up in a situation where we needed to decide on a behavior and stick with it.
As for using the persistence framework, it should do the trick, and you can update the settings to only save certain features, for example sorting, and groupBy, which should make the saving and loading very quick and lightweight.
-SteveZ
This behavior is done by design and will most likely not change.