Skip to content

Fix BindingEvaluator.ClearDataContext #18964

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

Merged
merged 2 commits into from
Jun 2, 2025

Conversation

MrJul
Copy link
Member

@MrJul MrJul commented Jun 1, 2025

What does the pull request do?

This PR fixes BindingEvaluator.ClearDataContext, which wasn't really clearing the data context.

What is the current behavior?

The data context is set to the binding evaluator itself, causing exceptions.
The issue was introduced in #18405.

What is the updated/expected behavior with this PR?

The data context is correctly set to null.

Fixed issues

@MrJul MrJul added bug regression backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Jun 1, 2025
@avaloniaui-bot
Copy link

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

@maxkatz6
Copy link
Member

maxkatz6 commented Jun 1, 2025

It might not matter here, but there two different ways to clear data context - set to null, preventing inheriting value, and calling AvaloniaObject.ClearValue to reset value store entry.

@MrJul
Copy link
Member Author

MrJul commented Jun 2, 2025

It might not matter here, but there two different ways to clear data context - set to null, preventing inheriting value, and calling AvaloniaObject.ClearValue to reset value store entry.

Indeed in this case it doesn't really matter since the object isn't attached to any tree. Setting it to null is probably the fastest in this case, since the BindingEvaluator may be reused later: the local values frame will be kept.

That said, I haven't measured it, and it's probably a micro optimization where it doesn't really matter: the vast majority of time spent would be in evaluating the various items' bindings, not clearing the data context once.

I'm keeping null here, we can revisit later if needed.

@MrJul MrJul added this pull request to the merge queue Jun 2, 2025
Merged via the queue into AvaloniaUI:master with commit 337f004 Jun 2, 2025
11 checks passed
@MrJul MrJul deleted the fix/bindingevaluator branch June 2, 2025 07:26
MrJul added a commit that referenced this pull request Jun 5, 2025
* Add failing test for BindingEvaluator.ClearDataContext

* Fix BindingEvaluator.ClearDataContext
@MrJul MrJul added backported-11.3.x and removed backport-candidate-11.3.x Consider this PR for backporting to 11.3 branch labels Jun 5, 2025
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.

ComboBox binding throws exception: Unable to cast object of type 'Avalonia.Controls.Utils.BindingEvaluator`1[System.Object]' to
3 participants