【问题标题】:UWP virtual keyboard pushes content upUWP 虚拟键盘向上推送内容
【发布时间】:2017-11-25 08:46:00
【问题描述】:

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

我看到您可以订阅打开和隐藏事件,但这并没有给我任何关于哪些 ui 元素可以保留或隐藏的选项。 https://docs.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>

【问题讨论】:

  • 如果没有足够的空间让键盘显示,通常会向上推内容。这里是这样吗?
  • 添加图片是否有助于回答这个问题?哦。我明白你的意思了。在本例中,图像与屏幕的大小大致相同。
  • 您可以尝试手动设置文本框获得焦点时的偏移量(负值)。

标签: keyboard uwp virtual


【解决方案1】:

是的,这就是 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);
        }
    }
}

【讨论】:

  • 您应该将此标记为答案。应得的。 ;)
猜你喜欢
  • 1970-01-01
  • 2019-08-14
  • 2018-05-14
  • 2022-08-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-07
  • 1970-01-01
相关资源
最近更新 更多