触摸屏平板电脑上的 WPF 滚动查看器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17294135/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Scrollviewer on touch screen tablet
提问by Sun
I'm writing a WPF application that is going to run on a full windows 8 touchscreen tablet (not RT).
我正在编写一个 WPF 应用程序,它将在完整的 Windows 8 触摸屏平板电脑(不是 RT)上运行。
However touch scrolling doesn't seem to be working. So I'm wondering if it's something I'm doing wrong or if it's even possible?
然而,触摸滚动似乎不起作用。所以我想知道这是我做错了什么还是有可能?
So, I have a WPF window with a scrollviewer. Within that scrollviewer I have a StackPanel which has loads of textblocks within it. See below:
所以,我有一个带有滚动查看器的 WPF 窗口。在该滚动查看器中,我有一个 StackPanel,其中包含大量文本块。见下文:
<ScrollViewer>
<StackPanel>
<TextBlock Text="Row 1" />
<TextBlock Text="Row 2" />
<TextBlock Text="Row 3" />
<TextBlock Text="Row 4" />
<TextBlock Text="Row 5" />
<TextBlock Text="Row 6" />
....
<TextBlock Text="Row 50" />
</StackPanel>
</ScrollViewer>
Now using the touchscreen I try to scroll the contents but it doesn't move. I can only scroll the contents using side scollbar which is not how I want this to work. Is it possible to get touch scrolling working with WPF? I'd also want to do the same with the grid.
现在使用触摸屏,我尝试滚动内容,但它不动。我只能使用 side scollbar 滚动内容,这不是我想要的工作方式。是否可以使用 WPF 进行触摸滚动?我也想对网格做同样的事情。
Thanks in advance.
提前致谢。
I'm using Visual Studio/Blend 2012.
我正在使用 Visual Studio/Blend 2012。
回答by Loetn
You can enable scrolling with the PanningModeproperty like this:
<ScrollViewer PanningMode="Both"></ScrollViewer>.
你能使用滚动PanningMode像这样的属性:
<ScrollViewer PanningMode="Both"></ScrollViewer>。
See: MSDN
请参阅:MSDN
Mouse support
鼠标支持
If you want to implement this behavior with the mouse, please read this article.
如果你想用鼠标实现这个行为,请阅读这篇文章。

