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

Use soft DataContext synchronization for Reactive UI controls #14477

Merged
merged 1 commit into from
Feb 4, 2024

Conversation

jp2masa
Copy link
Contributor

@jp2masa jp2masa commented Feb 3, 2024

What does the pull request do?

Improves the behavior of ReactiveUI controls by synchronizing DataContext and ViewModel only when it makes sense.

What is the current behavior?

Synchronization between DataContext and ViewModel is a bit aggressive. For example, setting ViewModel = null unsets DataContext, which becomes inherited and breaks compiled bindings. Also, at least on Windows Forms, WPF, and MAUI, these controls don't synchronize the properties at all.

What is the updated/expected behavior with this PR?

DataContext and ViewModel can be set independently: when one is unset, they are synchronized.

EDIT: DataContext and ViewModel can be set independently: when one is updated and its old value is equal to the other, the other is updated as well.

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

If !IsSet(one) then SetCurrentValue(one, other).

EDIT: If Object.ReferenceEquals(oldOne, other) then SetCurrentValue(other, one).

Checklist

Breaking changes

May break expected behavior.

Copy link
Member

@maxkatz6 maxkatz6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me but won't backport.

@maxkatz6
Copy link
Member

maxkatz6 commented Feb 4, 2024

@jp2masa it looks like ReactiveUI related tests are failing now.

@jp2masa jp2masa force-pushed the fix-reactiveui-viewmodel branch from 61d1b77 to 8db3f41 Compare February 4, 2024 04:03
@avaloniaui-bot
Copy link

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

@maxkatz6 maxkatz6 added this pull request to the merge queue Feb 4, 2024
Merged via the queue into AvaloniaUI:master with commit 0e9ce15 Feb 4, 2024
6 checks passed
@jp2masa jp2masa deleted the fix-reactiveui-viewmodel branch February 4, 2024 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants