C# 当软键盘显示时,如何保持页眉粘性?

C# 当软键盘显示时,如何保持页眉粘性?,c#,uwp,windows-10-universal,uwp-xaml,windows-10-mobile,C#,Uwp,Windows 10 Universal,Uwp Xaml,Windows 10 Mobile,我的UWP应用程序中有一个非常简单的页面,带有标题和几个文本框: <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto" /> <RowDefinition Height="*" /> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="Page Title!"

我的UWP应用程序中有一个非常简单的页面,带有标题和几个文本框:

<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>

在Windows10Mobile中,当底部文本框获得焦点并出现软键盘时,页面的全部内容会向上滚动,我不希望出现这种情况。我希望标题保持可见,scrollviewer滚动到文本框以保持在视图中。 我怎样才能做到这一点? 提前感谢。

您可以使用并将
TextBlock
添加到
CommandBar.Content
中,然后页眉将在页面中保持可见。页面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>

尝试添加框架元素并将除标题以外的所有项目添加到该框架,然后重试