Canvas で多数の UserControls をヒット テストしようとしています。HitTest() でビジュアル ツリー全体を処理したくないので、FilterCallback を使用して、UserControl のみをヒット テストするようにしています。
私の問題は、UserControl がヒットしないことです。ヒットするはずですが、ヒットしません。FilterCallback を使用すると、何もヒットしなかったことを返します。HitTest をビジュアル ツリーで実行すると、UserControl がスキップされます。
ここにいくつかのコードがあります:
<Canvas x:Name="Container">
<UserControl>
<Grid>
<Rectangle />
</Grid>
</UserControl>
<UserControl>
<Grid>
<Rectangle />
</Grid>
</UserControl>
</Canvas>
...
VisualTreeHelper.HitTest(Container, OnFilter, OnResult, myPoint);
...
private void OnResult(DependencyObject o)
{
//I'll get the Rectangle here, but never the userControl
}
private void OnFilter(DependencyObject o)
{
//I will get the UserControl here, but even when I do nothing more than continue, it will not trigger a visualHit. But the child rectangle will.
}