很难让 SurfaceScrollViewer 控件中的控件获得焦点
这有点奇怪,所以我希望也许其他人也遇到过这个问题,并且也许知道如何解决它。
我正在开发一个 WPF 应用程序,该应用程序最终将在 Windows 平板电脑上运行。因为它是触摸屏设备,所以我在显示要滚动的项目列表时使用了 SurfaceScrollViewer 控件,而且它工作得非常好。
我发现,如果我在 SurfaceScrollViewer 中显示 TextBox 控件,则无法编辑文本框,除非您非常快地重复点击它大约五到六次 - 只有这样它们才能获得焦点。
如果我使用 ScrollViewer 代替,它工作得很好。在桌面上运行时它也可以正常工作 - 这只是平板电脑上的问题。
有什么想法吗?
总而言之,这是主要结构: SurfaceScrollViewer / StackPanel / ItemsControl
即使我只有一个 TextBox 控件作为 ItemsControl 的 DataTemplate,它仍然遇到同样的问题。
哦 - 这也发生在按钮上。它不限于 TextBox 控件。
This is a bit of a weird one, so I was hoping maybe someone else has come across this as well, and maybe knows how to solve it.
I'm working on a WPF application that will ultimately be run on windows tablet PCs. Because it's a touch screen device, I've used the SurfaceScrollViewer control when showing lists of items to scroll through, and it works really nicely.
I've found that if I show a TextBox control in a SurfaceScrollViewer, you can't edit the textbox unless you tap it repeatedly about five or six times really fast - only then do they gain focus.
If I use a ScrollViewer instead, it works fine. It also works fine when running it on the desktop - this is only a problem on the tablet PC.
Any ideas?
To summarise, this is the main structure: SurfaceScrollViewer / StackPanel / ItemsControl
Even if I just have a single TextBox control as the DataTemplate of the ItemsControl, it still suffers from the same problem.
Oh - and this happens with buttons as well. It's not restricted to the TextBox control.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TextBox 和 Button 不知道如何像 Surface* 控件那样处理 Touch 事件。当您触摸文本框时,首先发送触摸事件。 TextBox 会忽略它,然后它会转到 SurfaceScrollViewer。 SSV 说“是的,好吧,我可以用这个做点什么”,因此它会处理该事件并处理该事件。捕获输入。 TextBox 不会获取与该触摸相关的进一步事件。
所以...技巧是要么处理 TextBox 上的 TouchDown 事件...或者更好,只需使用 SurfaceTextBox 控件即可为您完成此操作(以及其他有助于触摸的东西)。 Button/SurfaceButton 和许多其他标准控件也是如此。作为一般规则,只要存在 Surface 版本的控件,就使用它们。
TextBox and Button don't know how to handle Touch events like the Surface* controls do. When you touch the TextBox, first a touch event gets sent. The TextBox ignores it so then it goes to the SurfaceScrollViewer. SSV says "yeah ok, I can do something with this" so it handles the event & captures the input. TextBox gets no further events related to that touch.
So... the trick is to either handle to TouchDown event on your TextBox... or better yet, just use the SurfaceTextBox control which will do that for you (and other stuff to help with touch). The same goes for Button/SurfaceButton and many other standard controls. As a general rule, use the Surface versions of controls whenever they exist.