当前位置: 首页>>代码示例>>C#>>正文


C# StackPanel.HitTest方法代码示例

本文整理汇总了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)));
        }
开发者ID:highzion,项目名称:Granular,代码行数:38,代码来源:HitTestTest.cs


注:本文中的System.Windows.Controls.StackPanel.HitTest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。