Browse Source
Fix ReactiveUI regression, when DataContext type is different (#15423)
pull/14603/head
Max Katz
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
22 additions and
4 deletions
-
src/Avalonia.ReactiveUI/ReactiveUserControl.cs
-
src/Avalonia.ReactiveUI/ReactiveWindow.cs
-
tests/Avalonia.ReactiveUI.UnitTests/ReactiveUserControlTest.cs
|
|
|
@ -48,14 +48,15 @@ namespace Avalonia.ReactiveUI |
|
|
|
|
|
|
|
if (change.Property == DataContextProperty) |
|
|
|
{ |
|
|
|
if (Object.ReferenceEquals(change.OldValue, ViewModel)) |
|
|
|
if (ReferenceEquals(change.OldValue, ViewModel) |
|
|
|
&& change.NewValue is null or TViewModel) |
|
|
|
{ |
|
|
|
SetCurrentValue(ViewModelProperty, change.NewValue); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (change.Property == ViewModelProperty) |
|
|
|
{ |
|
|
|
if (Object.ReferenceEquals(change.OldValue, DataContext)) |
|
|
|
if (ReferenceEquals(change.OldValue, DataContext)) |
|
|
|
{ |
|
|
|
SetCurrentValue(DataContextProperty, change.NewValue); |
|
|
|
} |
|
|
|
|
|
|
|
@ -48,14 +48,15 @@ namespace Avalonia.ReactiveUI |
|
|
|
|
|
|
|
if (change.Property == DataContextProperty) |
|
|
|
{ |
|
|
|
if (Object.ReferenceEquals(change.OldValue, ViewModel)) |
|
|
|
if (ReferenceEquals(change.OldValue, ViewModel) |
|
|
|
&& change.NewValue is null or TViewModel) |
|
|
|
{ |
|
|
|
SetCurrentValue(ViewModelProperty, change.NewValue); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (change.Property == ViewModelProperty) |
|
|
|
{ |
|
|
|
if (Object.ReferenceEquals(change.OldValue, DataContext)) |
|
|
|
if (ReferenceEquals(change.OldValue, DataContext)) |
|
|
|
{ |
|
|
|
SetCurrentValue(DataContextProperty, change.NewValue); |
|
|
|
} |
|
|
|
|
|
|
|
@ -134,6 +134,22 @@ namespace Avalonia.ReactiveUI.UnitTests |
|
|
|
Assert.Same(vm2, view.ViewModel); |
|
|
|
} |
|
|
|
|
|
|
|
// https://github.com/AvaloniaUI/Avalonia/issues/15060
|
|
|
|
[Fact] |
|
|
|
public void Should_Not_Inherit_DataContext_Of_Wrong_Type() |
|
|
|
{ |
|
|
|
var view = new ExampleView(); |
|
|
|
var root = new TestRoot(view); |
|
|
|
|
|
|
|
Assert.Null(view.DataContext); |
|
|
|
Assert.Null(view.ViewModel); |
|
|
|
|
|
|
|
root.DataContext = this; |
|
|
|
|
|
|
|
Assert.Same(this, view.DataContext); |
|
|
|
Assert.Null(view.ViewModel); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void Should_Not_Overlap_Change_Notifications() |
|
|
|
{ |
|
|
|
|