Fixed issue where RowDetailsTemplate was getting the wrong DataContext #12174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello,
in this issue i noticed that the RowDetailsTemplate was getting the wrong DataContext when the first measurement pass was done which could cause a InvalidCastException or a StackOverflow (if a ContentControl is used).
What is the current behavior?
Avalonia/src/Avalonia.Controls.DataGrid/DataGridRows.cs
Lines 2967 to 2977 in 1940446
Right now the
detailsContent.DataContext
is only changed if the dataItem is not null.So when no list or an empty one is provided
detailsContent.DataContext
is not changed and it's still on the value provided by_rowsPresenter.Children.Add(detailsContent);
(which is the DataContext of the DataGrid).What is the updated/expected behavior with this PR?
I removed the null check of the dataItem so:
detailsContent.DataContext
will the item.detailsContent.DataContext
is set to null.After this change the issues mentioned above are not happening anymore.
I tested setting the ItemsSource:
Also no problem with RowDetailsVisibilityMode=Collapsed/Visible/VisibleWhenSelected
More details in the issue.
Fixed issues
Fixes #12106