本文整理汇总了C#中System.Windows.Controls.StackPanel.HitTest方法的典型用法代码示例。如果您正苦于以下问题:C# StackPanel.HitTest方法的具体用法?C# StackPanel.HitTest怎么用?C# StackPanel.HitTest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Controls.StackPanel
的用法示例。
在下文中一共展示了StackPanel.HitTest方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HitTestBasicTest
public void HitTestBasicTest()
{
StackPanel stackPanel1 = new StackPanel { Name = "stackPanel1", Background = Brushes.Transparent, IsRootElement = true };
StackPanel stackPanel2 = new StackPanel { Name = "stackPanel2", Background = Brushes.Transparent, Height = 100, Orientation = Orientation.Horizontal };
Border child1 = new Border { Name = "child1", Background = Brushes.Transparent, Height = 100, Width = 100 };
Border child2 = new Border { Name = "child2", Background = Brushes.Transparent, Height = 100 };
Border child3 = new Border { Name = "child3", Background = Brushes.Transparent, Width = 100 };
Border child4 = new Border { Name = "child4", Background = Brushes.Transparent, Width = 100 };
stackPanel1.Children.Add(child1);
stackPanel1.Children.Add(stackPanel2);
stackPanel1.Children.Add(child2);
stackPanel2.Children.Add(child3);
stackPanel2.Children.Add(child4);
// [child1] ]
// [child3][child4]
// [child2 ]
stackPanel1.Measure(Size.Infinity);
stackPanel1.Arrange(new Rect(stackPanel1.DesiredSize));
Assert.AreEqual(child1, stackPanel1.HitTest(new Point(50, 50)));
Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 50)));
Assert.AreEqual(child3, stackPanel1.HitTest(new Point(50, 150)));
Assert.AreEqual(child4, stackPanel1.HitTest(new Point(150, 150)));
Assert.AreEqual(child2, stackPanel1.HitTest(new Point(50, 250)));
Assert.AreEqual(child2, stackPanel1.HitTest(new Point(150, 250)));
stackPanel2.IsEnabled = false;
Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(50, 150)));
Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 150)));
child2.IsHitTestVisible = false;
Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(50, 250)));
Assert.AreEqual(stackPanel1, stackPanel1.HitTest(new Point(150, 250)));
}