Windows Phone:显示软件键盘后重新布局
Windows Phone: re-layout after software keyboard is shown
当显示软件键盘时,它会遮挡页面UI的一部分。这是不可取的。有没有办法自动更新UI布局,就像Android Activity的onConfigurationChanged一样?
似乎需要注册处理程序才能更新布局:
auto inputpane = InputPane::GetForCurrentView();
inputpane->Showing += ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(this, &MainPage::OnInputPaneVisibilityChanged);
inputpane->Hiding += ref new TypedEventHandler<InputPane^, InputPaneVisibilityEventArgs^>(this, &MainPage::OnInputPaneVisibilityChanged);
为了处理事件,我们可以在 event 参数中使用OccludedRect
,从中提取键盘的高度。首先,我们在 XAML 中保留一些 UI 元素,例如 SpaceForKeyboard
。例如:
<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>
然后在处理程序中,只需更改保留空间的大小:
void MainPage::OnInputPaneVisibilityChanged(InputPane^ sender, InputPaneVisibilityEventArgs^ args)
{
SpaceForKeyboard->Height = sender->OccludedRect.Height;
}
尽管应该很简单,但当显示/隐藏键盘时,将调用处理程序,并设置(或隐藏)虚拟网格以占用显示键盘的空间。
相关文章:
- 如何使用C/C++在MacOSX中获得键盘布局
- Vulkan验证层不断在VkQueuePresentKHR()上抛出图像布局错误
- 布局兼容类型的并集
- Qt自定义QPush按钮未显示在布局上
- 按钮悬停在 QT 中垂直布局的选项卡小部件中不起作用
- 调整布局上的 QGraphicsView 小部件的大小
- 如何在qt中将对象添加到现有布局中?--已解决
- 将布局映射到内存地址
- C++继承的虚拟类的内存布局
- 检查nullptr是否100%保护内存布局不受segfault影响
- C++ Python 的扩展 - 安全内存访问和内存布局
- QTree查看新行,没有布局就不可见已更改
- 类似元组的类模板的反向内存布局
- C++对象布局是否必须静态定义?
- 布局"新"是否取决于潜在的存储价值
- 对齐方式究竟如何影响内存布局和新放置的巴哈维?
- 插入新项目后,如何获得布局的高度
- C++新的运算符 - 内存布局
- Qt c++:如何在新项目打开后改变布局
- C++布局新不断给出编译错误