public void Adding_Already_Parented_Control_Should_Throw() { var root1 = new TestRoot(); var root2 = new TestRoot(); var child = new TestVisual(); root1.AddChild(child); Assert.Throws<InvalidOperationException>(() => root2.AddChild(child)); Assert.Equal(0, root2.GetVisualChildren().Count()); }
public void Adding_Children_Should_Fire_OnAttachedToVisualTree() { var child2 = new TestVisual(); var child1 = new TestVisual { Child = child2 }; var root = new TestRoot(); var called1 = false; var called2 = false; child1.AttachedToVisualTree += (s, e) => called1 = true; child2.AttachedToVisualTree += (s, e) => called2 = true; root.Child = child1; Assert.True(called1); Assert.True(called2); }
public void Should_Log_Binding_Error_When_Attached_To_Logical_Tree() { var target = new Decorator(); var root = new TestRoot { Child = target, DataContext = "foo" }; var called = false; LogCallback checkLogMessage = (level, area, src, mt, pv) => { if (level >= Logging.LogEventLevel.Warning) { called = true; } }; using (TestLogSink.Start(checkLogMessage)) { target.Bind(Decorator.TagProperty, new Binding("Foo")); } Assert.True(called); }
public void FindDescendantOfType_Finds_Nested_Child() { Button target; var root = new TestRoot { Child = new StackPanel { Children = { new StackPanel { Children = { (target = new Button()) } } } } }; Assert.Equal(target, root.FindDescendantOfType <Button>()); }
public void FindAncestorOfType_Finds_Ancestor_Of_Nested_Child() { Button target; var root = new TestRoot { Child = new StackPanel { Children = { new StackPanel { Children = { (target = new Button()) } } } } }; Assert.Equal(root, target.FindAncestorOfType <TestRoot>()); }
public void Root_Should_Retun_Self_As_VisualRoot() { var root = new TestRoot(); Assert.Same(root, ((IVisual)root).VisualRoot); }
public void Removing_Children_Should_Fire_OnDetachedFromVisualTree() { var child2 = new TestVisual(); var child1 = new TestVisual { Child = child2 }; var root = new TestRoot(); var called1 = false; var called2 = false; root.Child = child1; child1.DetachedFromVisualTree += (s, e) => called1 = true; child2.DetachedFromVisualTree += (s, e) => called2 = true; root.Child = null; Assert.True(called1); Assert.True(called2); }