标签:
/// <summary> /// 查找控件 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="root"></param> /// <returns></returns> public static T FindChildOfType<T>(Windows.UI.Xaml.DependencyObject root) where T : class { var queue = new Queue<Windows.UI.Xaml.DependencyObject>(); queue.Enqueue(root); while (queue.Count > 0) { var current = queue.Dequeue(); for (int i = 0; i < Windows.UI.Xaml.Media.VisualTreeHelper.GetChildrenCount(current); i++) { var child = Windows.UI.Xaml.Media.VisualTreeHelper.GetChild(current, i); var result = child as T; if (result != null) { return result; } queue.Enqueue(child); } } return null; }
在页面加载的时候
this.gvData.Loaded += (s1, e2) => { if (listData == null) listData = new System.Collections.ObjectModel.ObservableCollection<DataModel.DiabetesKnowledgeModel>(); scrollView = MiscHelper.FindChildOfType<ScrollViewer>(gvData); if (scrollView != null) { scrollView.ViewChanged += ScrollView_ViewChanged; } this.gvData.ItemsSource = listData; page = 1;
//加载内容 GetList(); };
有一个GetList()
isLoading = true;
//这里加载内容
再写scrollview的滑动事件
private bool isLoading = false;
private bool isRefresh = true;
private ScrollViewer scrollView;
private void ScrollView_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e) { if (isLoading) return; if (scrollView.ScrollableHeight > scrollView.ScrollableWidth) { if (scrollView.VerticalOffset >= scrollView.ScrollableHeight) { page++; isRefresh = false; GetKnowledgeList(); } } else { if (scrollView.HorizontalOffset >= scrollView.ScrollableWidth) { page++; isRefresh = false; GetKnowledgeList(); } } }
标签:
原文地址:http://www.cnblogs.com/lj940306/p/4678275.html