|
|
|
@ -249,6 +249,37 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void DataContextBeginUpdate_Should_Not_Be_Called_For_Controls_That_Dont_Inherit() |
|
|
|
{ |
|
|
|
using (CreateServices()) |
|
|
|
{ |
|
|
|
TestControl child; |
|
|
|
var popup = new Popup |
|
|
|
{ |
|
|
|
Child = child = new TestControl(), |
|
|
|
DataContext = "foo", |
|
|
|
}; |
|
|
|
|
|
|
|
var beginCalled = false; |
|
|
|
child.DataContextBeginUpdate += (s, e) => beginCalled = true; |
|
|
|
|
|
|
|
// Test for #1245. Here, the child's logical parent is the popup but it's not yet
|
|
|
|
// attached to a visual tree because the popup hasn't been opened.
|
|
|
|
Assert.Same(popup, ((ILogical)child).LogicalParent); |
|
|
|
Assert.Same(popup, child.InheritanceParent); |
|
|
|
Assert.Null(child.GetVisualRoot()); |
|
|
|
|
|
|
|
popup.Open(); |
|
|
|
|
|
|
|
// #1245 was caused by the fact that DataContextBeginUpdate was called on `target`
|
|
|
|
// when the PopupRoot was created, even though PopupRoot isn't the
|
|
|
|
// InheritanceParent of child.
|
|
|
|
Assert.False(beginCalled); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static IDisposable CreateServices() |
|
|
|
{ |
|
|
|
var result = AvaloniaLocator.EnterScope(); |
|
|
|
@ -304,5 +335,18 @@ namespace Avalonia.Controls.UnitTests.Primitives |
|
|
|
private class PopupContentControl : ContentControl |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
private class TestControl : Decorator |
|
|
|
{ |
|
|
|
public event EventHandler DataContextBeginUpdate; |
|
|
|
|
|
|
|
public new IAvaloniaObject InheritanceParent => base.InheritanceParent; |
|
|
|
|
|
|
|
protected override void OnDataContextBeginUpdate() |
|
|
|
{ |
|
|
|
DataContextBeginUpdate?.Invoke(this, EventArgs.Empty); |
|
|
|
base.OnDataContextBeginUpdate(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|