Get Scroll Viewer of List View Windows phone 8.1

340 views Asked by At

I need to get scroll viewer of List view to implement lazy loading in list view. For this I have referenced this http://windowsapptutorials.com/windows-phone-8-1/listview/lazy-loading-listview/ the function i used to retrieve scrollviewer is

public static ScrollViewer GetScrollViewer(DependencyObject depObj)
{
if (depObj is ScrollViewer) return depObj as ScrollViewer;

for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
    var child = VisualTreeHelper.GetChild(depObj, i);

    var result = GetScrollViewer(child);
    if (result != null) return result;
}
return null;
}

the problem is VisualTreeHelper.GetChildrenCount is always 0 and The function returns null. How to get scrollviewer of Listview ?

1

There are 1 answers

0
Kai Brummund On

WinRT xaml toolkit provides an extension for the VisualTreeHelper, that adds a GetFirstDecendantOfType. Just use that.

See Source on Codeplex.