In or application we use a xamgrid and we use the MVVM pattern. In the code behind I subscribe to the Rows.CollectionChanged because there is something I want to do at that point in code behind. But when I add an item to the source to which the xamgris ItemsSource is bound I see that I always get a Reset action and newItems and oldItems are allways null.
I modified one of your samples offered for a different issue but that already used the MVVM pattern. And I still see the same behavior.
Can you explain why it is so? I would expect to get the new Row and then be able to get its DataContext. And is there an alternative?
I attach here the modified sample.
I have been investigating into the behavior you are referring to, and this behavior is actually expected. When the XamGrid.Rows collection changes, it is internally cleared and repopulated, hence it raises a "Reset" action each time as we only appear to raise it for this "clear and repopulate" action. I would generally recommend against trying to handle this event, to be honest.
Is there a particular reason that you are looking to handle the XamGrid.Rows.CollectionChanged event in this case? I would generally recommend hooking the CollectionChanged event on your underlying ItemsSource to the XamGrid in this case. Each of your underlying items would represent a Row in the XamGrid, and so this would give you a much more accurate representation of whether or not a Row was added or removed, or if the collection was reset.
Please let me know if you have any other questions or concerns on this matter.
I understand even though I still find it strange. Maybe I should explain what I need.
When the user interactively sorts or filters a column the rows change; their order change and their count change. So I need in my Viewmodel a property that hold this collection of sorted/filteres row datacontexts. To achieve that I was looking into the Rows.CollectionChanged event.
Using the same sample (and enabling filtering with the FilterMenu on top) can you show me how I could do this?
I apologize for the delay in my response on this matter.
In order to achieve your requirement in this case, I would recommend handling the ColumnSorted and Filtered events of the XamGrid. In the handler for these events, you can then loop through the Rows collection of your XamGrid and update a collection in your view model with the data items to these Rows by utilizing the Row.Data property of each.
I have attached a modified version of the sample project you sent to demonstrate the above. I hope this helps you.