如何在UWP中将控件/UI元素与键盘一起移动 [英] How to move the control/UI elements along with the keyboard in UWP

查看:93
本文介绍了如何在UWP中将控件/UI元素与键盘一起移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有任何解决方案可以使应用程序在激活键盘时自动调整控件的位置.例如,在下图中,我要使屏幕上的这四个按钮与键盘相关联地移动.激活键盘后,按钮移至中间,键盘消失后向后移.

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.

推荐答案

这个想法是,您可以收听InputPane的显示和隐藏"事件.在事件处理程序中,您可以相对于键盘调整UI布局.

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.

有关InputPane的更多信息,请参考

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

有关动态对齐UI布局示例,请参阅 https://code.msdn.microsoft.com/windowsapps/Keyboard-Events -Sample-866ba41c

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

这篇关于如何在UWP中将控件/UI元素与键盘一起移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆