有没有办法在 WPF ScrollViewer 中启用触摸滚动? [英] Is there a way to touch-enable scrolling in a WPF ScrollViewer?

查看:28
本文介绍了有没有办法在 WPF ScrollViewer 中启用触摸滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 WPF 应用程序中创建一个表单,该表单将允许用户使用类似 iPhone 的手势滚动浏览可用字段.因此,我已将所有表单控件放在 ScrollViewer 内的 StackPanel 中,当屏幕上显示的元素过多时,滚动条会按预期显示.

I'm trying to create a form in a WPF application that will allow the user to use iPhone-like gestures to scroll through the available fields. So, I've put all my form controls inside a StackPanel inside a ScrollViewer, and the scrollbar shows up as expected when there are too many elements to be shown on the screen.

但是,当我尝试在支持触控的设备上进行测试时,平移手势(将手指向下放在表面上并向上拖动)并没有像我预期的那样向下移动可视区域.

However, when I try to test this on my touch-enabled device, a panning gesture (placing a finger down on the surface and dragging it upward) does not move the viewable area down as I would expect.

当我简单地将一些元素放入 ListView 时,触摸手势工作得很好.有没有办法在 ScrollViewer 中启用相同类型的行为?

When I simply put a number of elements inside a ListView, the touch gestures work just fine. Is there any way to enable the same kind of behavior in a ScrollViewer?

我的窗口结构如下:

 <Window x:Class="TestTouchScrolling.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<Grid>        
    <ScrollViewer Name="viewer" VerticalScrollBarVisibility="Auto">
        <StackPanel Name="panel">
            <StackPanel Orientation="Horizontal">
                <Label>Label 1:</Label>
                <TextBox Name="TextBox1"></TextBox>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label>Label 2:</Label>
                <TextBox Name="TextBox2"></TextBox>
            </StackPanel>
            <StackPanel Orientation="Horizontal">
                <Label>Label 3:</Label>
                <TextBox Name="TextBox3"></TextBox>
            </StackPanel>

            <!-- Lots more like these -->

        </StackPanel>
    </ScrollViewer>
</Grid>

推荐答案

你应该使用附加的属性:

You should use the attached properties:

  • ScrollViewer.PanningMode
  • ScrollViewer.PanningDeceleration
  • ScrollViewer.PanningRatio

在 ScrollViewer 默认样式中 PanningMode 默认为 None,但将其设置为其他值将启用触摸滚动.我目前正在调查在我的应用程序中使用此功能,并正在寻找一个好的减速和比率值...我可能只需要测试它们以找到运行良好的东西.

The PanningMode defaults to None in the ScrollViewer default style, but setting it to another value will enable touch scrolling. I'm currently investigating using this feature in my app and am looking for a good deceleration and ratio value... I'll probably just have to test them out to find something that works well.

这篇关于有没有办法在 WPF ScrollViewer 中启用触摸滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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