Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.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# 在HitTest中使用列表_C#_Wpf_Xaml - Fatal编程技术网

C# 在HitTest中使用列表

C# 在HitTest中使用列表,c#,wpf,xaml,C#,Wpf,Xaml,上的这一页代表了一个使用HitTest的示例,该示例在概念和。。。但有一件事我没有得到,那就是C代码指向的hitResultsList列表。我试图将其声明为列表: List<myShapeClass> hitResultsList = new List<myShapeClass>(); 谢谢。钥匙在这里,在回调中: // Return the result of the hit test to the callback. public HitTestResultBeh

上的这一页代表了一个使用HitTest的示例,该示例在概念和。。。但有一件事我没有得到,那就是C代码指向的hitResultsList列表。我试图将其声明为列表:

List<myShapeClass> hitResultsList = new List<myShapeClass>();

谢谢。

钥匙在这里,在回调中:

// Return the result of the hit test to the callback. 
public HitTestResultBehavior MyHitTestResult(HitTestResult result)
{
    // Add the hit test result to the list that will be processed after the enumeration.
    hitResultsList.Add(result.VisualHit);

    // Set the behavior to return visuals at all z-order levels. 
    return HitTestResultBehavior.Continue;
}
请注意,它正在添加
result.VisualHit
,而
result
是一个
HitTestResult
。因此,如果您查找该成员(),您将看到它是一个
DependencyObject

所以你想要:
列表

// Return the result of the hit test to the callback. 
public HitTestResultBehavior MyHitTestResult(HitTestResult result)
{
    // Add the hit test result to the list that will be processed after the enumeration.
    hitResultsList.Add(result.VisualHit);

    // Set the behavior to return visuals at all z-order levels. 
    return HitTestResultBehavior.Continue;
}