Windows Phone:显示软键盘后重新布局 [英] Windows Phone: re-layout after software keyboard is shown

查看:19
本文介绍了Windows Phone:显示软键盘后重新布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当显示软键盘时,它会遮挡部分页面 UI.这是不可取的.有没有办法像Android Activity的onConfigurationChanged一样自动更新UI布局?

When the software keyboard is shown, it occludes part of the page UI. That is undesirable. Is there a way to automatically update the UI layout just like Android Activity's onConfigurationChanged?

推荐答案

看来需要注册 handler 来更新布局:

It appears that one needs to register handler to update the layout:

auto inputpane = InputPane::GetForCurrentView();
inputpane->Showing += ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(this, &MainPage::OnInputPaneVisibilityChanged);
inputpane->Hiding += ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(this, &MainPage::OnInputPaneVisibilityChanged);

为了处理事件,我们可以在事件参数中使用 OccludedRect ,我们可以从中提取键盘占用的高度.首先,我们在 XAML 中保留一些 UI 元素,例如 SpaceForKeyboard.例如:

To handle the event, we can make use of OccludedRect in the event argument from which we can extract the height taken by the keyboard. First, we preserve some UI element, say SpaceForKeyboard, in the XAML. For example:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    <Grid.RowDefinitions>
    <Grid Grid.Row="0"> <!-- Main UI goes here --> </Grid>
    <Grid Grid.Row="1" x:Name="SpaceForKeyboard"> <!-- Dummy grid for the keyboard --> </Grid>
</Grid>

然后在处理程序中,更改保留空间的大小:

Then in the handler, just change the size for the preserved space:

void MainPage::OnInputPaneVisibilityChanged(InputPane^ sender, InputPaneVisibilityEventArgs^ args)
{
    SpaceForKeyboard->Height = sender->OccludedRect.Height;
}

应该很简单,当显示/隐藏键盘时,会调用处理程序并设置(或隐藏)虚拟网格以占据显示键盘的空间.

As simple as it should be, when the keyboard is shown/hidden, the handler is invoked and it sets (or hide) the dummy grid to occupy the space where the keyboard is shown.

这篇关于Windows Phone:显示软键盘后重新布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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