利用GestureListener的OnDragCompleted事件,实现列表向下滑动时,加载新的数据;
(不建议使用 Touch.FrameReported+=Touch_FrameReported;
此事件是全局的,如果没有注销事件,在离开页面后仍会得到响应,而这不是希望的效果)
前台代码:
monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: white"><Border>
<!- 此处放置ScrollViewer或 ListBox-->
<ScrollViewer/>
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener DragCompleted="OnDragCompleted" />
</toolkit:GestureService.GestureListener>
</Border>
后台:
/// <summary>
/// 上次刷新时间 (控制N秒内不允许多次刷新)
/// </summary>
private DateTime _lastRefreshTime = DateTime.Now.AddMinutes(-1);
#region 触摸滑动事件
/// <summary>
/// DragCompleted拖动结束
/// </summary>
private void OnDragCompleted(object sender, DragCompletedGestureEventArgs e)
{
double v_max = ScrollViewer1.ScrollableHeight;
double v_current = ScrollViewer1.VerticalOffset;
if (v_current / v_max > 0.9 && e.VerticalChange < 0)
{
//垂直向下,达到预期位置,可以加载数据了
Request();
}
//NoticeHelper.ShowPropMsg(msg, ColorType.ColorTip, 4);
}
#endregion
private void Request()
{
if (_lastRefreshTime.CompareTo(DateTime.Now.AddSeconds(-5)) < 0)
_lastRefreshTime = DateTime.Now;
else
return;
//低内存时,不予响应新的请求
// if (Sys.IsCurrentMemoryLow() && _pageNumber > 1) return;//低内存时,只允许请求0、1页的数据
//to do something..
}