Commit 711b2a7 1 parent d5ca06f commit 711b2a7 Copy full SHA for 711b2a7
File tree 3 files changed +22
-4
lines changed
tests/Avalonia.ReactiveUI.UnitTests
3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -48,14 +48,15 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
48
48
49
49
if ( change . Property == DataContextProperty )
50
50
{
51
- if ( Object . ReferenceEquals ( change . OldValue , ViewModel ) )
51
+ if ( ReferenceEquals ( change . OldValue , ViewModel )
52
+ && change . NewValue is null or TViewModel )
52
53
{
53
54
SetCurrentValue ( ViewModelProperty , change . NewValue ) ;
54
55
}
55
56
}
56
57
else if ( change . Property == ViewModelProperty )
57
58
{
58
- if ( Object . ReferenceEquals ( change . OldValue , DataContext ) )
59
+ if ( ReferenceEquals ( change . OldValue , DataContext ) )
59
60
{
60
61
SetCurrentValue ( DataContextProperty , change . NewValue ) ;
61
62
}
Original file line number Diff line number Diff line change @@ -48,14 +48,15 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang
48
48
49
49
if ( change . Property == DataContextProperty )
50
50
{
51
- if ( Object . ReferenceEquals ( change . OldValue , ViewModel ) )
51
+ if ( ReferenceEquals ( change . OldValue , ViewModel )
52
+ && change . NewValue is null or TViewModel )
52
53
{
53
54
SetCurrentValue ( ViewModelProperty , change . NewValue ) ;
54
55
}
55
56
}
56
57
else if ( change . Property == ViewModelProperty )
57
58
{
58
- if ( Object . ReferenceEquals ( change . OldValue , DataContext ) )
59
+ if ( ReferenceEquals ( change . OldValue , DataContext ) )
59
60
{
60
61
SetCurrentValue ( DataContextProperty , change . NewValue ) ;
61
62
}
Original file line number Diff line number Diff line change @@ -134,6 +134,22 @@ public void Should_Inherit_DataContext()
134
134
Assert . Same ( vm2 , view . ViewModel ) ;
135
135
}
136
136
137
+ // https://github.com/AvaloniaUI/Avalonia/issues/15060
138
+ [ Fact ]
139
+ public void Should_Not_Inherit_DataContext_Of_Wrong_Type ( )
140
+ {
141
+ var view = new ExampleView ( ) ;
142
+ var root = new TestRoot ( view ) ;
143
+
144
+ Assert . Null ( view . DataContext ) ;
145
+ Assert . Null ( view . ViewModel ) ;
146
+
147
+ root . DataContext = this ;
148
+
149
+ Assert . Same ( this , view . DataContext ) ;
150
+ Assert . Null ( view . ViewModel ) ;
151
+ }
152
+
137
153
[ Fact ]
138
154
public void Should_Not_Overlap_Change_Notifications ( )
139
155
{
You can’t perform that action at this time.
0 commit comments