Is there a way to prevent the screen to shift upwards when the soft keyboard is shown in a Windows Phone app?
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.
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.
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. 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()
use the X component of a translate transform to move the textbox around on the screen. There is a good blog post about it from 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
It helped me better than Alex's article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With