Silverlight FindElementsInHost相对于控件空间的坐标不是整个页面

Silverlight FindElementsInHost相对于控件空间的坐标不是整个页面,silverlight,silverlight-3.0,visualtreehelper,Silverlight,Silverlight 3.0,Visualtreehelper,我使用VisualTreeHelper方法FindElementsInHostCoordinates在给定的X和Y位置查找ListBoxItem。但是,X和Y值似乎与整个页面中的点相关,而不仅仅是我感兴趣的列表框(即使我将该元素传递到方法的子树参数中)。下面,这是指从ListBox派生的自定义控件 foreach (UIElement element in VisualTreeHelper.FindElementsInHostCoordinates(new Point(X, Y), this))

我使用VisualTreeHelper方法FindElementsInHostCoordinates在给定的X和Y位置查找ListBoxItem。但是,X和Y值似乎与整个页面中的点相关,而不仅仅是我感兴趣的列表框(即使我将该元素传递到方法的子树参数中)。下面,这是指从ListBox派生的自定义控件

foreach (UIElement element in VisualTreeHelper.FindElementsInHostCoordinates(new Point(X, Y), this))
{
    if (element is ListBoxItem)
    {
        int index = this.ItemContainerGenerator.IndexFromContainer(element);
        break;
    }
}
因此,(0,0)将相对于整个插件的左上角,而不是列表框的左上角。我是否需要自己在这里做一些数学工作(在代码中)来将页面坐标转换为ListBox坐标,或者是否有其他方法来执行命中测试来判断给定的X和Y点是否在ListBoxItem上

谢谢。

这是我自己想出来的(哇)。我确定了控件的顶部和左侧值,然后将X和Y值添加到控件内部:

GeneralTransform gt = this.TransformToVisual(Application.Current.RootVisual as UIElement);
Point offset = gt.Transform(new Point(0, 0));
double controlTop = offset.Y + Y;
double controlLeft = offset.X + X;
因此,我可以传递相对于控件的X和Y值,但这段代码将它转换为全局坐标


为我工作,嘿!,在这个问题上没有风滚草徽章。:)