When developing an application using the ListView as a confidence rendering carrier, we often need to do some interactive logic by monitoring the position state of the ScrollBar (ScrollViewer). The most direct embodiment is the delay load, (load more on the slide, pull down to get updated data).
We can accomplish these logic through the ScrollViewer viewchanged event.
So here's the problem. (- -! Not that excavator ...)
How do I get the ScrollViewer object from the ListView?
1. we can get the ScrollViewer object under the ListView in such a way. The method is defined as follows.
This method can get the ScrollViewer object under the ListView.
public static T findvisualchildbyname<t> (DependencyObject Parent, string name) where T:dependencyobject
{
Try
{
for (int i = 0; I < Visualtreehelper.getchildrencount (parent); i++)
{
var child = Visualtreehelper.getchild (parent, I);
String controlname = child. GetValue (Control.nameproperty) as String;
if (string. IsNullOrEmpty (name) | | ControlName = = name) && Child is T)
{
return child as T;
}
Else
{
T result = findvisualchildbyname<t> (child, name);
if (result! = NULL)
return result;
}
}
return null;
}
Catch
{
return null;
}
}
2.//In the loaded event of the ListView, call the Findvisualchildbyname<t> method to get the ScrollView object.
private void Listview1_loaded (object sender, RoutedEventArgs e)
{
Call the Findvisualchildbyname<t> method to get the ScrollView object.
ScrollViewer ScrollViewer = findvisualchildbyname<scrollviewer> (ListView1, "ScrollViewer");
Give this ScrollViewer the event.
Scrollviewer.viewchanged + = scrollviewer_viewchanged;
}
Windows Phone 8.1 Development: How to get the ScrollViewer object from the ListView