UWP虚拟键盘推动内容

Hay*_*ydn 3 keyboard virtual uwp

我有一个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>
Run Code Online (Sandbox Code Playgroud)

机器人的图象有暗藏的面孔的

Hay*_*ydn 6

是的,这就是贾斯汀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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

固定图像

  • 你应该把它标记为答案.应得的.;) (3认同)