Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 什么是Silverlight';s FindElementsInHost坐标是否等效于WPF?_C#_Wpf_Silverlight_Hittest_Visualtreehelper - Fatal编程技术网

C# 什么是Silverlight';s FindElementsInHost坐标是否等效于WPF?

C# 什么是Silverlight';s FindElementsInHost坐标是否等效于WPF?,c#,wpf,silverlight,hittest,visualtreehelper,C#,Wpf,Silverlight,Hittest,Visualtreehelper,我想在WPF画布组件上执行一个矩形命中测试,以获得被矩形框架元素重叠的控件。我找到了Silverlight的VisualTreeHelper.FindElementsInHostCoordinates方法,但显然它在WPF中不可用 实现这种功能的最佳方法是什么?最接近的等效方法是。它的工作原理与Silverlight的FindElementsInHostCoordinates有很大不同,但您应该能够根据自己的需要使用它。假设您在Silverlight中有这样的调用 var result = Vi

我想在WPF画布组件上执行一个矩形命中测试,以获得被矩形框架元素重叠的控件。我找到了Silverlight的
VisualTreeHelper.FindElementsInHostCoordinates
方法,但显然它在WPF中不可用


实现这种功能的最佳方法是什么?

最接近的等效方法是。它的工作原理与Silverlight的FindElementsInHostCoordinates有很大不同,但您应该能够根据自己的需要使用它。

假设您在Silverlight中有这样的调用

var result = VisualTreeHelper.FindElementsInHostCoordinates(myPoint, myUIElement);
那么这个WPF代码应该有一个等价的
结果

var result = new List<DependencyObject>(); 
                         //changed from external edits, because VisualHit is
                         //only a DependencyObject and may not be a UIElement
                         //this could cause exceptions or may not be compiling at all
                         //simply filter the result for class UIElement and
                         //cast it to IEnumerable<UIElement> if you need
                         //the very exact same result including type

VisualTreeHelper.HitTest(
    myUiElement,
    null,
    new HitTestResultCallback(
        (HitTestResult hit)=>{
            result.Add(hit.VisualHit);
            return HitTestResultBehavior.Continue;
        }),
    new PointHitTestParameters(myPoint));
var result=newlist();
//已从外部编辑更改,因为VisualHit是
//只能是DependencyObject,不能是UIElement
//这可能会导致异常或根本无法编译
//只需过滤UIElement类的结果,然后
//如果需要,将其转换为IEnumerable
//完全相同的结果,包括类型
VisualTreeHelper.HitTest(
myUiElement,
无效的
新HittTestResultCallback(
(HitTestResult命中)=>{
结果.添加(hit.VisualHit);
返回HitTestResultBehavior。是否继续;
}),
新的PointHitTestParameters(myPoint));
在您的特殊情况下,您可能希望使用
GeometryHitTestParameters
而不是
PointHitTestParameters
来执行Rect测试