开发者

Difficulty getting controls in a SurfaceScrollViewer control to gain focus

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, an开发者_如何学运维d 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜