XAMGrid Rows.CollectionChanged is always a Reset


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.



Thank you.

  • 27000
    Offline posted

    Hello Sundance,

    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.

Reply Children