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.