C# 在HitTest中使用列表
上的这一页代表了一个使用HitTest的示例,该示例在概念和。。。但有一件事我没有得到,那就是C代码指向的hitResultsList列表。我试图将其声明为列表: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
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;
}