public void ShouldFindVisualAncestor() { var root = new Grid(); var child1a = new Border(); var child1b = new TextBlock(); var child3 = new TextBlock(); root.Children.Add(child1a); root.Children.Add(child1b); child1a.Child = child3; child3.FindFirstVisualAncestor<Grid>().ShouldBe(root); child3.FindFirstVisualAncestor<Border>().ShouldBe(child1a); child3.FindFirstVisualAncestor<Border>().ShouldNotBe(child1b); child3.FindFirstVisualAncestor<StackPanel>().ShouldBe(null); }