简体   繁体   English

在 WP7 中显示软键盘时防止屏幕向上滚动?

[英]Prevent screen scrolling up when soft keyboard is shown in WP7?

Is there a way to prevent the screen to shift upwards when the soft keyboard is shown in a Windows Phone app? Windows 电话应用程序显示软键盘时,有没有办法防止屏幕向上移动?

I have a text box which is located in the upper half of the screen, so when the soft keyboard is shown, it doesn't cover the text box.我有一个位于屏幕上半部分的文本框,因此当显示软键盘时,它不会覆盖文本框。 However, when the textbox is tapped, the screen still shifts up.但是,当点击文本框时,屏幕仍然向上移动。

Can this be prevented?这可以预防吗?

I spent quite some time trying to find a solution to this - in my case I wanted the page header to remain at the top of the screen instead of scrolling away when the keyboard opened.我花了很多时间试图找到解决这个问题的方法——在我的例子中,我希望页面 header 保留在屏幕顶部,而不是在键盘打开时滚动离开。

The best I found was the solution described in the post below, which uses changes in the frame's TranslateTransform (which is triggered by the keyboard opening / closing) to change the size of the top margin and therefore the space for available content.我找到的最好的解决方案是下面的帖子中描述的解决方案,它使用框架的 TranslateTransform 中的更改(由键盘打开/关闭触发)来更改上边距的大小,从而更改可用内容的空间。

http://sorokoletov.com/2011/08/windows-phone-70-handling-text-entry-screens/ http://sorokoletov.com/2011/08/windows-phone-70-handling-text-entry-screens/

If you have a screen with a number of elements, you may want to consider explicitly changing the layout to accommodate the smaller space.如果您的屏幕包含许多元素,您可能需要考虑明确更改布局以适应较小的空间。

I'm not convinced there is an easy way to change the scroll position when the keyboard is opened.我不相信有一种简单的方法可以在打开键盘时更改滚动条 position。 Though I can think of several workarounds:虽然我可以想到几种解决方法:

  • put everything in a scrollviewer, when the textboxes focusevent is called scroll the scroll viewer to keep the item you are interested in in view using ScrollToVerticalOffset()将所有内容放在滚动查看器中,当调用文本框 focusevent 时滚动滚动查看器以使用 ScrollToVerticalOffset() 保持您感兴趣的项目在视图中

  • use the X component of a translate transform to move the textbox around on the screen.使用 translate 转换的 X 组件在屏幕上移动文本框。 There is a good blog post about it from Alex Sorokoletov . Alex Sorokoletov有一篇关于它的好博客文章。

I found this scrolling all the way to the bottom of all comments in the article cited above:我发现它一直滚动到上面引用的文章中所有评论的底部:

Scrollviewer and Multiline Textbox Windows Phone 滚动查看器和多行文本框 Windows 电话

It helped me better than Alex's article.它比 Alex 的文章对我的帮助更大。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM