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
405
XAMGrid Rows.CollectionChanged is always a Reset
posted

Hello,

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.

https://emerson.sendthisfile.com/c.jsp?t=gtY9klGb8CcfbqA7zyjpxs8C&n=f2Tqhbjt7rlkH5lfFvXdbVvG

https://emerson.sendthisfile.com/f2Tqhbjt7rlkH5lfFvXdbVvG

Thank you.

Parents
  • 28350
    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