如何检测滚动查看器是否到达Winrt的底部 [英] How to detect if the scroll viewer reaches bottom in winrt

查看:38
本文介绍了如何检测滚动查看器是否到达Winrt的底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道检测ScrollViewer是否到达底部,右侧等的最佳方法是什么.

I'm wondering what's the best approach to detect if a ScrollViewer reaches the bottom, right etc.

我想我可以通过同时使用鼠标的PointerWheelChanged和触摸的ManipulationDelta来实现.在这些事件处理程序中,我可以记录Horizo​​ntalOffset来找出滚动条何时到达终点.但我认为可能会有更好的方法.

I think I can achieve that by using both PointerWheelChanged for mouse and ManipulationDelta for touch. In these event handlers, I can record the HorizontalOffset to find out when will the scroller reach the end. But I think there could be a better way to do it.

我找到了这个

I've found this article. But the compression visual states seem not working in winrt. The CurrentStateChanging event method is not getting called.

我还检查了另一条文章.但这仅适用于滚动条,而不是通用方法.

I also checked another article. But it just works for scroll bar, not a generic approach.

任何人都知道解决此问题的最佳方法是什么?

Anyone knows what's the best way to solve this problem?

推荐答案

XAML:

<ScrollViewer
    x:Name="sv"
    ViewChanged="OnScrollViewerViewChanged">
    <Rectangle
        x:Name="rect"
        Width="2000"
        Height="2000"
        Fill="Yellow"
        Margin="10" />
</ScrollViewer>

后面的代码:

private void OnScrollViewerViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
    var verticalOffset = sv.VerticalOffset;
    var maxVerticalOffset = sv.ScrollableHeight; //sv.ExtentHeight - sv.ViewportHeight;

    if (maxVerticalOffset < 0 ||
        verticalOffset == maxVerticalOffset)
    {
        // Scrolled to bottom
        rect.Fill = new SolidColorBrush(Colors.Red);
    }
    else
    {
        // Not scrolled to bottom
        rect.Fill = new SolidColorBrush(Colors.Yellow);
    }
}

这篇关于如何检测滚动查看器是否到达Winrt的底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆