Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Implement DataContext update notifications on the DataGrid

Open aldelaro5 opened this issue 2 years ago • 4 comments

What does the pull request do?

This fixes #5661 by allowing the DataGrid to notify its cells that their DataContext is about to be changed. This allows controls who needs to have these notifications (such as any SelectingItemsControls) to get notified before the DataContext changes. This is needed if the DataContext of the DataGrid changes to null which can occur when switching to another Tab from a TabControl ancestor as it prevents a clear of the items which would cause a binding target on the SelectedIndex to be set to -1.

What is the current behavior?

If a DataGrid has a ComboBox in one of its cell and this DataGrid is inside a TabControl, it is possible to trigger an unwanted set to the SelectedIndex binding to -1 by switching to another tab. This happens because since this ComboBox never gets notified that its DataContext is about to change, it will not avoid clearing its items once the change actually happen since this DataContext becomes null in this context.

What is the updated/expected behavior with this PR?

To have the DataGrid inform its cells that their DataContext is about to change and to also be informed when the change has completed.

How was the solution implemented (if it's not obvious)?

I call the Notify event passing the cell's content for each cell. This is done because the cells aren't reachable from the DataGrid's logical tree.

Checklist

  • [ ] Added unit tests (if possible)?
  • [ ] Added XML documentation to any related classes?
  • [ ] Consider submitting a PR to https://github.com/AvaloniaUI/Documentation with user documentation

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes #5661

aldelaro5 avatar Aug 04 '22 02:08 aldelaro5

CLA assistant check
All CLA requirements met.

dnfadmin avatar Aug 04 '22 02:08 dnfadmin

Not sure what the CI is doing: it was failing last time, I just rebased and it seems to work...somewhat?

aldelaro5 avatar Aug 07 '22 03:08 aldelaro5

You can test this PR using the following package version. 0.10.999-cibuild0022966-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

avaloniaui-team avatar Aug 07 '22 03:08 avaloniaui-team

@aldelaro5 integration tests for mac are failing currently, because mac device is offline. That's fine for this PR, can be ignored.

maxkatz6 avatar Aug 07 '22 05:08 maxkatz6

You can test this PR using the following package version. 0.10.999-cibuild0023158-beta. (feed url: https://nuget.avaloniaui.net/repository/avalonia-all/index.json) [PRBUILDID]

avaloniaui-team avatar Aug 13 '22 04:08 avaloniaui-team