Reputation: 13
It's a very simple question. I have a number of stackpanels inside of a scrollview. I want them to raise an event when there are visible to the user(via scrolling).
Thanks in advance.
Upvotes: 1
Views: 117
Reputation: 2385
Check this page out. It shows how to determine if your element is in the ScrollViewers viewport.
// 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.
}
Upvotes: 2