码迷,mamicode.com
首页 > 其他好文 > 详细

下拉加载

时间:2015-07-26 18:45:59      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:

 

/// <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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!