"Scrolled into Viewport"-like event in Silverlight
In Silverligh开发者_JS百科t, is there any way to get a notification event if a Control
(or any FrameworkElement
) has been scrolled into the viewport and is now visible?
I want to implement something like the Lazy Load Images jQuery Plugin.
Could largely solve this by now. With the help of some extension methods of the Silverlight Toolkit, we can find the inner vertical ScrollBar
for any FrameworkElement
by
Scrollbar myScrollBar = myContainerElement.GetVisualDescendants()
.OfType<ScrollBar>()
.Where(foundScrollBar => foundScrollBar.Orientation == Orientation.Vertical)
.FirstOrDefault();
We can then attach to its events like Scroll
or ValueChanged
.
Then there is another helpful Toolkit extension method we can use:
Rect? rect = myElement.GetBoundsRelativeTo(myViewportElement);
if (rect.HasValue)
{
if (rect.Value.Top <= myViewportElement.ActualHeight)
{
// do some stuff
}
}
This Silverlight forums post from October 2009 discusses the lack of a "VisibilityChanged" event in Silverlight and comes up with the solution of using the "Loaded" event:
The Loaded event is usually a good place to start retrieving data.
With tab controls, the Loaded event for an element on a tab won't be raised until a user navigates to the tab the element is on.
I know it's not strictly analogous with your situation, but it might be worth trying to see if it works for a Control
or FrameworkElement
.
精彩评论