如何在软键盘显示时保持页面 header 粘滞?

How to keep page header sticky when soft keyboard shows?

我的 UWP 应用程序中有一个非常简单的页面,其中包含 header 和几个文本框:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <TextBlock Grid.Row="0" Text="Page Title!" />

    <ScrollViewer Grid.Row="1" VerticalScrollMode="Auto">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <TextBox Grid.Row="0" Margin="20" />
            <TextBox Grid.Row="1" Margin="20" />
            <TextBox Grid.Row="2" Margin="20" />
            <TextBox Grid.Row="3" Margin="20" />
            <TextBox Grid.Row="4" Margin="20" />
        </Grid>
    </ScrollViewer>
</Grid>

在 Windows 10 移动版中,当底部文本框获得焦点并出现软键盘时,页面的全部内容向上滚动,我不希望这样。我希望 header 保持可见并且滚动查看器滚动到文本框以保持可见。 我怎样才能做到这一点? 提前致谢。

您可以使用 CommandBar 并将 TextBlock 添加到 CommandBar.Content,然后 header 将在页面中保持可见。页面 xaml 代码应如下所示,

<Page.TopAppBar>
    <CommandBar Background="Transparent" OverflowButtonVisibility="Collapsed">
        <CommandBar.Content>
            <TextBlock  Text="Page Title!" Margin="20" />
        </CommandBar.Content>
    </CommandBar>
</Page.TopAppBar>
<Grid>
    <ScrollViewer  VerticalScrollMode="Auto">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <TextBox Grid.Row="0" Margin="20" />
            <TextBox Grid.Row="1" Margin="20" />
            <TextBox Grid.Row="2" Margin="20" />
            <TextBox Grid.Row="3" Margin="20" />
            <TextBox Grid.Row="4" Margin="20" />
        </Grid>
    </ScrollViewer>
</Grid>