Touch Scrolling ScrollViewer in WPF App with RealTimeStylus Disabled

泪湿孤枕 提交于 2019-12-03 09:34:39

Another option is to add arrow buttons around the content. We've used this to great effect on a touch screen kiosk. It's a bit more work, but could be made into a custom control. The only code I have supports vertical scrolling.

It should be easy enough to add horizontal scrolling as well. In the code below, there are two buttons, called Less and More above and below the scroller.

    double Epsilon = .001;

    private void Scroller_ScrollChanged(object sender, ScrollChangedEventArgs e)
    {
        if ( Scroller.ScrollableHeight > 0 ) {
            Less.Visibility = Math.Abs(Scroller.VerticalOffset - 0) > Epsilon ? Visibility.Visible : Visibility.Hidden;
            More.Visibility = Scroller.VerticalOffset + Scroller.ViewportHeight < Scroller.ExtentHeight ? Visibility.Visible : Visibility.Hidden;
        } else {
            Less.Visibility = More.Visibility = Visibility.Hidden;
        }

        if (Scroller.ExtentHeight / Scroller.ViewportHeight > 2)
        {
            SearchPanel.Visibility = Visibility.Visible;
        }
    }

    private void Less_Click(object sender, RoutedEventArgs e)
    {
        Sounds.Click();
        Scroller.PageUp();
    }

    private void More_Click(object sender, RoutedEventArgs e)
    {
        Sounds.Click();
        Scroller.PageDown();
    }

Can you try SurfaceScrollViewer instead of normal ScrollViewer.

SurfaceScrollViewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!