Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue where RowDetailsTemplate was getting the wrong DataContext #12174

Merged
merged 2 commits into from Jul 28, 2023
Merged

Fixed issue where RowDetailsTemplate was getting the wrong DataContext #12174

merged 2 commits into from Jul 28, 2023

Conversation

GundlackFlorian
Copy link

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?

if(VisibleSlotCount > 0)
dataItem = DataConnection.GetDataItem(0);
var detailsContent = RowDetailsTemplate.Build(dataItem);
if (detailsContent != null)
{
_rowsPresenter.Children.Add(detailsContent);
if (dataItem != null)
{
detailsContent.DataContext = dataItem;
}
detailsContent.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

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:

  • If the dataItem is set, detailsContent.DataContext will the item.
  • If there no dataItem, the detailsContent.DataContext is set to null.

After this change the issues mentioned above are not happening anymore.
I tested setting the ItemsSource:

  • Empty list -> works
  • List with items -> works
  • null -> works

Also no problem with RowDetailsVisibilityMode=Collapsed/Visible/VisibleWhenSelected

More details in the issue.

Fixed issues

Fixes #12106

@GundlackFlorian
Copy link
Author

@dotnet-policy-service agree

@timunie
Copy link
Contributor

timunie commented Jul 13, 2023

Thx 🙏

@avaloniaui-team
Copy link
Contributor

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

@GundlackFlorian
Copy link
Author

GundlackFlorian commented Jul 13, 2023

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

After testing with the build (i'm using the test project of the issue), the StackOverflow is fixed, but not the InvalidCastException.
I moved the detailsContent.DataContext = dataItem before the _rowsPresenter.Children.Add(detailsContent).

Waiting for the next PRBUILD to test again.

@avaloniaui-team
Copy link
Contributor

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

@GundlackFlorian
Copy link
Author

GundlackFlorian commented Jul 13, 2023

11.0.999-cibuild0037679-beta works !

@grokys grokys added this pull request to the merge queue Jul 27, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 27, 2023
@maxkatz6 maxkatz6 added this pull request to the merge queue Jul 28, 2023
Merged via the queue into AvaloniaUI:master with commit 9808a44 Jul 28, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants