keyboard - UWP 虚拟键盘将内容向上推

标签 keyboard uwp virtual

我有一个 UWP 应用程序,当虚拟键盘打开时,我的机器人脸会被推上去。当虚拟键盘打开时,是否可以让滚动查看器保持原位并让文本框保持在 View 中。

我看到您可以订阅打开和隐藏事件,但这并没有给我任何可以保留或隐藏 ui 元素的选项。 https://learn.microsoft.com/en-us/windows/uwp/input-and-devices/respond-to-the-presence-of-the-touch-keyboard

<Page
    x:Class="VirtualKeyboardFix.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:VirtualKeyboardFix"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <ScrollViewer >
            <Image Source="image.png" />
        </ScrollViewer>
        <TextBox HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Margin="10" />
    </Grid>
</Page>

Image of robot with hidden face

最佳答案

是的,这就是 Justin XL 的答案。非常感谢。如果您想将其作为回复而不是评论发布,那么我会将其标记为答案。

以防万一有人遇到同样的问题。

namespace VirtualKeyboardFix
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();

            InputPane.GetForCurrentView().Showing += MainPage_Showing;
            InputPane.GetForCurrentView().Hiding += MainPage_Hiding;
        }

        private void MainPage_Showing(InputPane sender, InputPaneVisibilityEventArgs args)
        {
            args.EnsuredFocusedElementInView = false;
            InputTextBox.Margin = new Thickness(10, 10, 10, args.OccludedRect.Height + 10);
        }

        private void MainPage_Hiding(InputPane sender, InputPaneVisibilityEventArgs args)
        {
            args.EnsuredFocusedElementInView = false;
            InputTextBox.Margin = new Thickness(10, 10, 10, 10);
        }
    }
}

Fixed Image

关于keyboard - UWP 虚拟键盘将内容向上推,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44693167/

相关文章:

c# - 是否可以在 Windows 10 上调整 BLE 连接间隔?

c++ - 当成员析构函数运行时,类具有什么类型的虚函数?

c++ - vftable 性能损失与 switch 语句

在平板电脑上打开键盘时 HTML 元素移动

objective-c - 在编辑模式下 uitextview 上的单个选项卡,关闭键盘

java - 键盘按键重复率和延迟

C# UWP WriteableBitmap 到 MediaClip 的转换

c# - 如何在不手动设置的情况下将绑定(bind)属性作为参数传递

c++ - 抽象类 C++

ios - 当我快速单击单元格中的文本字段时,键盘没有出现