-
Notifications
You must be signed in to change notification settings - Fork 742
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
fix(selector): Don't push null selection to binding when unloading Selector #5936
Conversation
…lector When a Selector (eg ListView or ComboBox) is removed from the visual tree, if its DataContext is inherited and ItemsSource and SelectedItem are both bound, the UWP behavior is that the ItemsSource will be set to null, which will set SelectedItem to null, but the null selection won't be pushed through the two-way binding. This change approximates the same behavior under Uno's binding system by detecting that scenario and not updating two-way bindings when an inherited DataContext is being cleared.
The build 28203 found UI Test snapshots differences: Details
|
The build 28203 found UI Test snapshots differences: Details
|
The build 28203 found UI Test snapshots differences: Details
|
for (var storeIndex = 0; storeIndex < _childrenStores.Count; storeIndex++) | ||
{ | ||
var store = _childrenStores[storeIndex]; | ||
store.OnParentPropertyChangedCallback(instanceRef, property, eventArgs); | ||
var childStore = _childrenStores[storeIndex]; | ||
var propagateUnregistering = (_unregisteringInheritedProperties || _parentUnregisteringInheritedProperties) && property == _dataContextProperty; | ||
#if !HAS_EXPENSIVE_TRYFINALLY // Try/finally incurs a very large performance hit in mono-wasm - https://github.com/dotnet/runtime/issues/50783 | ||
try | ||
#endif | ||
{ | ||
if (propagateUnregistering) | ||
{ | ||
childStore._parentUnregisteringInheritedProperties = true; | ||
} | ||
childStore.OnParentPropertyChangedCallback(instanceRef, property, eventArgs); | ||
} | ||
#if !HAS_EXPENSIVE_TRYFINALLY // Try/finally incurs a very large performance hit in mono-wasm - https://github.com/dotnet/runtime/issues/50783 | ||
finally | ||
#endif | ||
{ | ||
if (propagateUnregistering) | ||
{ | ||
childStore._parentUnregisteringInheritedProperties = false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably move this to another method for readability
{ | ||
// This guards against the scenario where inherited DataContext is removed when the view is removed from the visual tree, | ||
// in which case 2-way bindings should not be updated. | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a debug/trace logging message there, like similar operations
The build 28275 found UI Test snapshots differences: Details
|
The build 28275 found UI Test snapshots differences: Details
|
The build 28275 found UI Test snapshots differences: Details
|
When a Selector (eg ListView or ComboBox) is removed from the visual tree, if its DataContext is inherited and ItemsSource and SelectedItem are both bound, the UWP behavior is that the ItemsSource will be set to null, which will set SelectedItem to null, but the null selection won't be pushed through the two-way binding.
This change approximates the same behavior under Uno's binding system by detecting that scenario and not updating two-way bindings when an inherited DataContext is being cleared.
GitHub Issue (If applicable): partially addresses #5852
PR Type
What kind of change does this PR introduce?
What is the current behavior?
What is the new behavior?
PR Checklist
Please check if your PR fulfills the following requirements:
Screenshots Compare Test Run
results.Other information
Internal Issue (If applicable):