hitArea
= new EllipseGeometry(
new Point(Canvas.GetLeft(myShape), Canvas.GetTop(myShape)),
1.0,
1.0);
VisualTreeHelper.HitTest(
myShape, null,
new HitTestResultCallback(HitTestCallback),
new GeometryHitTestParameters(hitArea));
public HitTestResultBehavior HitTestCallback(HitTestResult result)
{
if (result.VisualHit == myShape)
{
//// This shape is on the visible area.
}
}
2 回答
您可以使用HitTest对Canvas的边界矩形执行命中测试 . 有关详细信息,请参阅Hit Testing in the Visual Layer并参考hit testing with DrawingVisuals的示例 .
这应该有帮助吗?
通过所有儿童形状的画布迭代并检查每个myShape的以下内容....