Windows Phone 8检查堆栈面板是否在可见区域中

时间:2013-07-11 07:42:14

标签: windows-phone-8

这是一个非常简单的问题。我在scrollview中有很多堆栈面板。我希望他们在用户可见时(通过滚动)引发事件。

提前致谢。

1 个答案:

答案 0 :(得分:2)

检查this page。它显示了如何确定您的元素是否在ScrollViewers视口中。

// position of your visual inside the scrollviewer    
GeneralTransform childTransform = ContainedObject.TransformToAncestor(ScrollViewerObj);
Rect rectangle = childTransform.TransformBounds(new Rect(new Point(0,0),ContainedObject.RenderSize));

//Check if the elements Rect intersects with that of the scrollviewer's
Rect result = Rect.Intersect(new Rect(new Point(0, 0), ScrollViewerObj.RenderSize),rectangle);
//if result is Empty then the element is not in view
if (result == Rect.Empty)
{
//....
}
else
{
//obj is partially Or completely visible
//skip or bring obj in view.
}