Windows Phone 7 (WP7) Development of ListBox paging Loading

Source: Internet
Author: User

I believe you have seen the paging loading of ListBox in many applications. However, in WP7 development, this feature seems to be less intuitive (because there are not so many scrollend events ), when I was learning to develop this function, the first step was Baidu Google Bing, in order not to duplicate the wheel. In fact, many people are asking this question. There is only one common concern, that is, how to judge how to scroll The ListBox scroll to the bottom, this article only expands on how to judge whether to scroll to the end. I remember seeing an English article implementing this effect. It was very complicated to write and many classes. I was too lazy to continue reading it ......, Later, I saw a very simple method from a Chinese forum, and I had to lament the ingenuity of the Chinese.

Private void upload (Object sender, routedeventargs e) {list <scrollbar> scrollbarlist = getvisualchildcollection <scrollbar> (lstbizs); foreach (scrollbar in scrollbarlist) {If (scrollbar. orientation = system. windows. controls. orientation. horizontal) {} else {scrollbar. valuechanged + = new routedpropertychangedeventhandler <double> (verticalscrollbar_valuechanged );}}} Private void verticalscrollbar_valuechanged (Object sender, routedeventargs e) {scrollbar = (scrollbar) sender; object valueobj = scrollbar. getvalue (scrollbar. valueproperty); object maxobj = scrollbar. getvalue (scrollbar. maximumproperty); If (valueobj! = NULL & maxobj! = NULL) {double value = (double) valueobj; double max = (double) maxobj-1.0; If (value> = max) {// read data on the next page }}}

 

        public static List<T> GetVisualChildCollection<T>(object parent) where T : UIElement        {            List<T> visualCollection = new List<T>();            GetVisualChildCollection(parent as DependencyObject, visualCollection);            return visualCollection;        }        private static void GetVisualChildCollection<T>(DependencyObject parent, List<T> visualCollection) where T : UIElement        {            int count = VisualTreeHelper.GetChildrenCount(parent);            for (int i = 0; i < count; i++)            {                DependencyObject child = VisualTreeHelper.GetChild(parent, i);                if (child is T)                {                    visualCollection.Add(child as T);                }                else if (child != null)                {                    GetVisualChildCollection(child, visualCollection);                }            }        }

  

 

This code is very concise and concise, not original, but it runs very well and is really useful after I take it directly. My only modification is "Double max = (double) maxobj-1.0;". Here, the value is the current value of scrollbar, and Max is the maximum value, however, if you pull the scroll bar to the bottom to start loading the data on the next page, a pause will appear, so the rule I set is "loading the next page data when the user pulls the scroll bar to the last line". The value of 1.0 is modified as needed.

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.