简体   繁体   English

如何在UWP中将控件/ UI元素与键盘一起移动

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

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. 这里可能会有一些类似的问题,但是我在搜索结果中看不到它们,也许他们在标题上使用了一些不同的单词,因此,如果重复此问题,则可以将链接粘贴到评论中或任何地方,将不胜感激。

图片插图

The idea is you can listen to the Showing and Hiding event of the InputPane. 这个想法是您可以收听InputPane的Showing and Hiding事件。 In the event handler, you adjust your UI layout with respect to the keyboard. 在事件处理程序中,您可以相对于键盘调整UI布局。

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 有关InputPane的详细信息,请参阅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 要动态对齐UI布局示例,请参阅https://code.msdn.microsoft.com/windowsapps/Keyboard-Events-Sample-866ba41c

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

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