Windows Phone 8.1 Development: How to get the ScrollViewer object from the ListView

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.