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

Made OneTime bindings update on DataContext changes #17683

Merged
merged 3 commits into from
Dec 15, 2024

Conversation

MrJul
Copy link
Member

@MrJul MrJul commented Dec 3, 2024

What does the pull request do?

This PR changes how bindings with a OneTime mode work, to behave the same way as in WPF (and as currently documented), updating their target not only a single time, but once per data context change.

In addition, null data contexts are now considered valid values for bindings without a path.

What is the current behavior?

OneTime bindings are evaluated only once.
Bindings without a path ({Binding}) are considered "pending" (they don't update their target nor call their converter) while their data context is null.

What is the updated/expected behavior with this PR?

OneTime bindings are evaluated once per data context, like in WPF.
null is now a valid DataContext for pathless bindings, and will use the configured TargetNullValue and Converter, also matching WPF.

Notes

As explained in #17587 (comment), the two changes are entangled: with the previous behavior we can't have null be a valid data context without breaking OneTime bindings using them.

Unit tests have been added.
One unit test has been deleted, since one-time bindings now don't stop on the first update.

Fixed issues

@MrJul MrJul added bug customer-priority Issue reported by a customer with a support agreement. area-bindings labels Dec 3, 2024
@avaloniaui-bot
Copy link

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

@maxkatz6 maxkatz6 requested a review from grokys December 3, 2024 23:22
@timunie
Copy link
Contributor

timunie commented Dec 4, 2024

This probably closes more issues.

#17474
#17649

@MrJul
Copy link
Member Author

MrJul commented Dec 4, 2024

This probably closes more issues.

#17474 #17649

Thanks! I've tested the two repros and they now work properly with the changes from this PR.
I've added them to the OP.

@MrJul
Copy link
Member Author

MrJul commented Dec 11, 2024

Added as a backport candidate due to the fix for DataContext bindings, an issue that regularly pops up.

@MrJul MrJul added this pull request to the merge queue Dec 11, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 11, 2024
@MrJul MrJul added this pull request to the merge queue Dec 15, 2024
Merged via the queue into AvaloniaUI:master with commit 9d03a01 Dec 15, 2024
11 checks passed
@MrJul MrJul deleted the feature/onetime-binding-refresh branch December 15, 2024 11:21
maxkatz6 pushed a commit that referenced this pull request Dec 19, 2024
* Add failing tests for OneTime and null data context bindings

* Made OneTime bindings update on DataContext changes

Also allows null as a valid value for bindings without path

* Remove now obsolete test
@maxkatz6 maxkatz6 added backported-11.2.x and removed backport-candidate-11.2.x Consider this PR for backporting to 11.2 branch labels Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-bindings backported-11.2.x bug customer-priority Issue reported by a customer with a support agreement.
Projects
None yet
6 participants