Touch Scrolling ScrollViewer in WPF App with RealTimeStylus Disabled

女生的网名这么多〃 提交于 2019-12-04 15:25:51

问题


We are working on a WPF 4.5 application that will be run on Windows 8 computers with touchscreen monitors.

We have disabled support for the RealTimeStylus following the directions on the MSDN, since we have some views that need multitouch support through WM_TOUCH.

The problem is that disabling the RealTimeStylus support seems to also disable the user's ability to scroll a ScrollViewer using touch - normally the user can pan around ScrollViewers with their fingers, but if RealTimeStylus support is disabled, it does not seem possible to do this. The ScrollViewer's PanningMode is set to "Both".

Is it possible to combine these things in a WPF application, or are they mutually exclusive?


回答1:


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();
    }



回答2:


Can you try SurfaceScrollViewer instead of normal ScrollViewer.

SurfaceScrollViewer



来源:https://stackoverflow.com/questions/18254920/touch-scrolling-scrollviewer-in-wpf-app-with-realtimestylus-disabled

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