现在我以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. 【BZOJ】【3261】最大异或和

    可持久化Trie 嗯……同样搞个前缀异或和,然后将x与sum异或一下,就是在[l-1,r-1]中找x^sum的最大异或值了.同样可持久化Trie搞搞即可(模板还是没背全啊……sad /******** ...

  2. Leetcode#49 Anagrams

    原题地址 Anagram:变位词.两个单词是变位词关系的条件是:组成单词的字符相同,只是顺序不同 第一次看这道题看了半天没明白要干嘛,丫就不能给个样例输入输出么..后来还是看网上其他人的总结知道是怎么 ...

  3. short-path problem (Floyd) 分类: ACM TYPE 2014-09-01 23:58 100人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> using namespace std; cons ...

  4. byte和hexstring,int,string等的转换类

    public class HexConversion { /** * 16进制数的字符串转字节数组(16进制转字节数组) * * @param hexString * 16进制字符串 * @retur ...

  5. uitableviewcell 和 uibutton

    如果cell上面只有一个button  可以设置button.tag=IndexPath.Row;得到当前点击的行数,设置button属性的时候,可以设置一个全局的button来记住当前点击的butt ...

  6. ASP.NET页面刷新的实现方法总结

    先看看ASP.NET页面刷新的实现方法: 第一: private void Button1_Click( object sender, System.EventArgs e ) { Response. ...

  7. Razor语法学习

    原文:http://www.cnblogs.com/youring2/archive/2011/07/24/2115254.html 1.Razor的文件类型 Razor支持两种文件类型,分别是.cs ...

  8. 动态修改 NodeJS 程序中的变量值

    如果一个 NodeJS 进程正在运行,有办法修改程序中的变量值么?答案是:通过 V8 的 Debugger 接口可以!本文将详细介绍实现步骤. 启动一个 HTTP Server 用简单的 Hello ...

  9. Subclasses

    Given a collection of numbers, return all possible subclasses. public class Solution { public List&l ...

  10. Tech Stuff - Mobile Browser ID (User-Agent) Strings

    Tech Stuff - Mobile Browser ID (User-Agent) Strings The non-mobile stuff is here (hint: you get jerk ...