How to move the control/UI elements along with the keyboard in UWP

冷暖自知 提交于 2020-01-06 19:57:04

问题


I'm wondering if there any solution that could make the app automatically adjust the controls position when the keyboard is activated. For example, in the image below, I want to make those four button on the screen move dependently with keyboard. When the keyboard is activated, buttons move to the center and move back when the keyboard is gone.

There might be some similar questions here but I couldnt see them in the search result, maybe they are using some different words on title so if this question is duplicated it will be appreciated if you guys could paste the link on comment or whereever.


回答1:


The idea is you can listen to the Showing and Hiding event of the InputPane. In the event handler, you adjust your UI layout with respect to the keyboard.

For example, you can realign the button relative to the height of the keyboard.

For more information on InputPane, refer to https://msdn.microsoft.com/EN-US/library/windows/apps/windows.ui.viewmanagement.inputpane.aspx

For dynamically align the UI layout example, refer to https://code.msdn.microsoft.com/windowsapps/Keyboard-Events-Sample-866ba41c



来源:https://stackoverflow.com/questions/34649733/how-to-move-the-control-ui-elements-along-with-the-keyboard-in-uwp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!