现在我以listview为例来讲述下拉刷新的功能!

在xaml中设置listview一定要设置一个这样的属性,IsSwipeEnabled=false,然后再listview控件的前面要布局下拉刷新的图标及提示,在listview控件的后面也要布局上拉时的提示信息。

现在我将个人的布局展现出来,仅供大家参考!

 <Grid Name="layoutCtlRoot" MinWidth="240">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Border Name="recRefresh" Height="0" Margin="0" MaxHeight="800" VerticalAlignment="Bottom">
<Grid>
<Grid Margin="10" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="64"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel VerticalAlignment="Bottom" HorizontalAlignment="Center">
<Image Name="imgArrow" Style="{StaticResource ProgressArrowStyle}">
<Image.RenderTransform>
<RotateTransform x:Name="imageRotateTransform" Angle="0"/>
</Image.RenderTransform>
</Image>
<ProgressRing Name="prgRefresh" Style="{StaticResource ProgressRingStyle}"/>
</StackPanel>
<StackPanel VerticalAlignment="Bottom" Grid.Column="1">
<TextBlock Name="txtOperationTip" Style="{StaticResource TipsContentStyle}"/>
<TextBlock Name="txtOperationTime" Style="{StaticResource TipsContentStyle}"/>
</StackPanel>
</Grid>
<Border Background="#99999999" VerticalAlignment="Bottom" Height="1"/>
</Grid>
</Border>
<ListView Name="ForumList" Grid.Row="1" IsSwipeEnabled="False" ItemContainerStyle="{StaticResource ListItemBaseStyle}"/>
<Border Name="recLoad" Height="0" Grid.Row="2" MaxHeight="800">
<Grid VerticalAlignment="Top" Margin="0,10">
<Border Background="#99999999" VerticalAlignment="Top" Height="1"/>
<StackPanel Name="splNextPageLoading" HorizontalAlignment="Center" Orientation="Horizontal" Visibility="Collapsed">
<ProgressRing Style="{StaticResource ProgressRingStyle}" Visibility="Visible"/>
<TextBlock Text="正在加载…" Margin="13" Style="{StaticResource TipsContentStyle}"/>
</StackPanel>
</Grid>
</Border>
</Grid>

然后在后台就要实现下拉刷新的正真效果呢!

这里特别要指出的要注册这样一个事件,  this.LayoutUpdated += ForumList_LayoutUpdated;不然就实现不了!

也要注册listview的触摸事件,例如:

this.ForumList.ManipulationStarted+=ForumList_ManipulationStarted;
            this.ForumList.ManipulationDelta+=ForumList_ManipulationDelta;
            this.ForumList.ManipulationCompleted+=ForumList_ManipulationCompleted;

思路就是这样的,现在我就讲后台的逻辑也给大家参考!

  DispatcherTimer toptimer = new DispatcherTimer();
DispatcherTimer timer = new DispatcherTimer();
private ScrollViewer listViewScrollViewer; private double listviewItemHeight = -;
private int optLimitHeight = ;
private bool isInPrpcessing = false; private Point eventStartPoint; private double lastDeltaHandledY = ; private ObservableCollection<dynamic> listDataItems = new ObservableCollection<dynamic>(); //移动开始位置
private Point moveStartPoint;
//是否可以移动
private bool canMove = false; public ListPage()
{
this.InitializeComponent(); this.imgArrow.Source = new BitmapImage(new Uri(@"ms-appx:///Assets/pullrefresh_arrow.png",UriKind.RelativeOrAbsolute));
this.LayoutUpdated += ForumList_LayoutUpdated;
this.recRefresh.SizeChanged+=recRefresh_SizeChanged;
this.ForumList.ManipulationStarted+=ForumList_ManipulationStarted;
this.ForumList.ManipulationDelta+=ForumList_ManipulationDelta;
this.ForumList.ManipulationCompleted+=ForumList_ManipulationCompleted;
//this.ForumList.SelectionChanged+=ForumList_SelectionChanged;
}
  private void ForumList_LayoutUpdated(object sender, object e)
{
if (this.Height.Equals(double.NaN) && this.Parent != null)
{
this.Height = ((Windows.UI.Xaml.FrameworkElement)(this.Parent)).ActualHeight;
} if (listViewScrollViewer == null)
{
listViewScrollViewer = FindVisualElement<ScrollViewer>(VisualTreeHelper.GetParent(this));
listViewScrollViewer.ManipulationMode = ManipulationModes.All;
} for (int i = ; i < this.ForumList.Items.Count; i++)
{
ListViewItem item = this.ForumList.ItemContainerGenerator.ContainerFromIndex(i) as ListViewItem; if (item != null && item.ManipulationMode != ManipulationModes.All)
{
item.ManipulationMode = ManipulationModes.All; if (listviewItemHeight < )
{
listviewItemHeight = ((Windows.UI.Xaml.FrameworkElement)(item)).ActualHeight;
}
}
}
} private static T FindVisualElement<T>(DependencyObject container) where T : DependencyObject
{
Queue<DependencyObject> childQueue = new Queue<DependencyObject>();
childQueue.Enqueue(container); while (childQueue.Count > )
{
DependencyObject current = childQueue.Dequeue(); T result = current as T;
if (result != null && result != container)
{
return result;
} int childCount = VisualTreeHelper.GetChildrenCount(current);
for (int childIndex = ; childIndex < childCount; childIndex++)
{
childQueue.Enqueue(VisualTreeHelper.GetChild(current, childIndex));
}
} return null;
}
 private void recRefresh_SizeChanged( object sender,SizeChangedEventArgs e)
{
if (e.NewSize.Height > this.optLimitHeight && !isInPrpcessing)
{
if (!this.txtOperationTip.Text.Equals("松开刷新…"))
{
this.txtOperationTip.Text = "松开刷新…";
this.ImgStoryBoard.Begin();
}
}
} private void ForumList_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e)
{
eventStartPoint = e.Position;
lastDeltaHandledY = 0;
if (!isInPrpcessing)
{
this.txtOperationTip.Text = "下拉刷新列表…";
}
e.Handled = true;
}
private void ForumList_ManipulationDelta(object sender,ManipulationDeltaRoutedEventArgs e)
{
double offset = e.Cumulative.Translation.Y - lastDeltaHandledY;
if (listViewScrollViewer.VerticalOffset < 3)
{
double height = recRefresh.Height + offset;
recRefresh.Height = height > 0 ? height : 0;
if (offset < 0 && recRefresh.Height <= 0)
{
//向上滑动且刷新Panel未显示时滚动条下移
listViewScrollViewer.ScrollToVerticalOffset(listViewScrollViewer.VerticalOffset-offset/listviewItemHeight);
}
}
else if (listViewScrollViewer.VerticalOffset >= listViewScrollViewer.ScrollableHeight - 1)
{
double height = recLoad.Height - offset;
recLoad.Height = height > 0 ? height : 0;
if (offset > 0 && recLoad.Height <= 0)
{
listViewScrollViewer.ScrollToVerticalOffset(listViewScrollViewer.VerticalOffset - offset / listviewItemHeight);
}
}
else
{
listViewScrollViewer.ScrollToVerticalOffset(listViewScrollViewer.VerticalOffset-offset/listviewItemHeight);
}
lastDeltaHandledY = e.Cumulative.Translation.Y;
e.Handled = true;
} private void ForumList_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
{
if (listViewScrollViewer != null)
{
double offset = listViewScrollViewer.VerticalOffset;
double total = listViewScrollViewer.ScrollableHeight;
if (offset <= 3 || offset > total - 2)
{
DoListItemsSwipe();
}
}
}
/// <summary>
/// 数据加载后是否可下拉刷新
/// </summary>
public static readonly DependencyProperty RefreshableProperty = DependencyProperty.Register("Refreshable", typeof(bool), typeof(ListPage), new PropertyMetadata(true));
public bool Refreshable
{
get
{
return (bool)base.GetValue(RefreshableProperty);
}
set
{
base.SetValue(RefreshableProperty, value); if (!value)
{
this.imgArrow.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
this.prgRefresh.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
this.txtOperationTip.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
this.txtOperationTime.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
}
}
private void DoListItemsSwipe()
{
if (recRefresh.Height > 0)
{
if (recRefresh.Height > optLimitHeight && this.Refreshable)
{
recRefresh.Height = 96;
imgArrow.Visibility = Visibility.Collapsed;
prgRefresh.Visibility = Visibility.Visible;
if (!this.isInPrpcessing)
{
System.Diagnostics.Debug.WriteLine(this.isInPrpcessing);
DoListDataSourceRefresh();
}
}
else
{
recRefresh.Height = 0;
}
listViewScrollViewer.ScrollToVerticalOffset(2.05);
}
if (recLoad.Height > 0)
{
if (recLoad.Height > optLimitHeight)
{
recLoad.Height = 68;
splNextPageLoading.Visibility = Visibility.Visible;
if (!this.isInPrpcessing)
{
DoListDataLoadNextPage();
}
}
else
{
recLoad.Height = 0;
}
}
}
private void DoListDataSourceRefresh()
{ this.isInPrpcessing = true;
this.txtOperationTip.Text = "加载数据中";
this.isInPrpcessing = false;
this.recRefresh.Height = 0;
this.imgArrow.Visibility = Windows.UI.Xaml.Visibility.Visible;
this.prgRefresh.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
this.ImgStoryBoard.Begin(); //箭头复位
}
private void DoListDataLoadNextPage()
{
this.recLoad.Height = 0;
splNextPageLoading.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
public event SelectionChangedEventHandler SelectionChanged;
private void ForumList_SelectionChanged( object sender,SelectionChangedEventArgs e)
{
SelectionChanged(sender,e);
}

在win8中如何实现下拉刷新的功能的更多相关文章

  1. refreshcontrol 实现下拉刷新的功能

    该组件实现下拉刷新的功能.不过该组件是用在ScrollView的内部的,为ScrollView添加一个下拉刷新的功能.当ScrollView的垂直方向的偏移量scrollY:0的时候,手指往下拖拽Sc ...

  2. 关于mui 中popover与下拉刷新冲突问题

    最近用mui做app混合式开发时,作为一个后端开发,高前端确实有点吃了,期间遇到的问题肯定也不少.这两天app做更新,为了装逼,将更新的提示搞得好看些,用到了mui中的popover,结果把自己整死了 ...

  3. Android开发学习之路-下拉刷新怎么做?

    因为最近的开发涉及到了网络读取数据,那么自然少不了的就是下拉刷新的功能,搜索的方法一般是自己去自定义ListView或者RecyclerView来重写OnTouch或者OnScroll方法来实现手势的 ...

  4. Windows phone应用开发[22]-再谈下拉刷新

    几周之前在博客更新一篇Windows phone应用开发[18]-下拉刷新 博文,有很多人在微博和博客评论中提到了很多问题.其实在实际项目中我基于这篇博文提出解决问题思路优化了这个解决方案.为了能够详 ...

  5. UWP的一种下拉刷新实现

    简介 我们最近实现了一个在UWP中使用的下拉刷新功能,以满足用户的需求,因为这是下拉刷新是一种常见的操作方式,而UWP本身并不提供这一机制. 通过下拉刷新这一机制,可以让移动端的界面设计变得更加简单, ...

  6. [转]Android下拉刷新完全解析,教你如何一分钟实现下拉刷新功能

    版权声明:本文出自郭霖的博客,转载必须注明出处. 转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9255575 最近项目中需要用到L ...

  7. 【转载】 ionic 的 下拉刷新 与 上拉加载

    这篇文章是讲解 Ioinc中怎么实现 下拉刷新和上拉加载的.也是我们日常做项目是必不可少的功能.有兴趣的小伙伴可以来学习一下. 更多关于 IONIC 的资源: http://www.aliyue.ne ...

  8. IOS学习笔记34—EGOTableViewPullRefresh实现下拉刷新

    移动应用开发中有这么一种场景,就是在列表中显示的数据刷新,有点击刷新按钮刷新的,也有现在最流行的由Twitter首先推出的下拉刷新功能,在IOS中,使用下拉刷新更新UITableView中的数据也用的 ...

  9. Android下拉刷新底部操作栏的隐藏问题

    最近自己编写下拉刷新的时候,发现了一个问题,就是有一个需求是这样的:要求页面中是一个Tab切换界面,一个界面有底部操作栏,不可下拉刷新,另一个界面没有底部操作栏,但可以下拉刷新. 按照平常的做法,我在 ...

随机推荐

  1. Codeforces Round #FF (Div. 2)

    又一场中国场,果然注定被虐的场... A,B:都很水,差不多模拟就好了: C题:CF难得的题意简洁, 我们可以预处理出从左到右递增的数列个数, 举个例子:1 3 2 4 5 7 L[I]       ...

  2. 大漠推荐的教程:创建你自己的AngularJS -- 第一部分 Scopes

    创建你自己的AngularJS -- 第一部分 Scopes http://www.html-js.com/article/1863

  3. O2O模式成功案例分享 汲取精华化为己用

    本文通过分享一些公司的o2o成功案例让您了解什么是O2O,o2o的优势,o2o模式有哪些,未来我们要如何做o2o才更有竞争力,学牛人的o2o创新玩法,摸索适合自己的o2o思路.拥抱o2o - 传统企业 ...

  4. maven 构建spring ssh mybatis 配置

    详情参与 http://blog.csdn.net/yuguiyang1990/article/details/8811817 前面我们使用Maven构建了Struts2项目,这里我们来试一下Hibe ...

  5. javascript设计模式-抽象工厂模式

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. mysql去除重复查询的SQL语句基本思路

    SELECT R.* FROM trans_flow R, (SELECT order_no, MAX(status_time) AS status_time FROM trans_flow GROU ...

  7. windbg内核诊断方式--转载

    一.WinDbg是什么?它能做什么? WinDbg是在windows平台下,强大的用户态和内核态调试工具.它能够通过dmp文件轻松的定位到问题根源,可用于分析蓝屏.程序崩溃(IE崩溃)原因,是我们日常 ...

  8. 由浅入深了解Thrift之客户端连接池化

    一.问题描述 在上一篇<由浅入深了解Thrift之服务模型和序列化机制>文章中,我们已经了解了thrift的基本架构和网络服务模型的优缺点.如今的互联网圈中,RPC服务化的思想如火如荼.我 ...

  9. poj 3469

    Dual Core CPU Time Limit: 15000MS   Memory Limit: 131072K Total Submissions: 18120   Accepted: 7818 ...

  10. cf div2 238 D

    D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input standard input out ...