Silverlight Scroll to Viewport Event

In Silverlight, is there a way to get a notification event if the viewport is scrolled Control

(or any FrameworkElement

) and is now visible?

I want to implement something like Lazy Load Images jQuery Plugin .

+2


a source to share


2 answers


This problem can now be resolved. With some of the Silverlight Toolkit extension methods, we can find the inner vertical ScrollBar

for any FrameworkElement

on

Scrollbar myScrollBar = myContainerElement.GetVisualDescendants()
        .OfType<ScrollBar>()
        .Where(foundScrollBar => foundScrollBar.Orientation == Orientation.Vertical)
        .FirstOrDefault();

      

Then we can attach to its events, for example, Scroll

or ValueChanged

.



Then there is another useful Toolkit extension method that we can use:

Rect? rect = myElement.GetBoundsRelativeTo(myViewportElement);
if (rect.HasValue)
{
    if (rect.Value.Top <= myViewportElement.ActualHeight)
    {
        // do some stuff
    }
}

      

+3


a source


This Silverlight forum post from October 2009 discusses the lack of the "VisibilityChanged" event in Silverlight and suggests a solution to use the Downloaded Event:

The loading event is usually a good place to start fetching data.

With tab controls, the Loaded event for an item in a tab will not be raised until the user navigates to the tab the item is in.



I know this is not strictly analogous to your situation, but it might be worth trying if it works for Control

or FrameworkElement

.

+1


a source







All Articles