2

我有一个非常简单的页面,其中包含页眉、页脚和可滚动的内容。我的 iOS 和 UWP 应用似乎运行良好。当我进入页面时,iOS 和 UWP 从顶部的 ScrollView Scrolled 开始,但 Android 似乎向下滚动,直到您可以看到至少一个按钮。

我的页面看起来像这样(页眉、大滚动内容和页脚):

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Grid Height="64"
          Background="Blue">
        <TextBlock Text="Header"
                   Margin="20" />
    </Grid>

    <ScrollViewer Grid.Row="1">
        <StackPanel>
            <TextBlock Text="Top"
                       VerticalAlignment="Top"
                       Height="500" />
            
            <TextBlock Text="Content"
                       FontSize="66"
                       Margin="0,0,0,300" />
            <Button Content="button"
                    Margin="0,0,0,300"/>

            <TextBlock Text="Bottom"
                       VerticalAlignment="Bottom" />
        </StackPanel>
    </ScrollViewer>



    <Grid Height="44"
          Background="Green"
          Grid.Row="2">
        <TextBlock Text="Footer"
                   Margin="10" />
    </Grid>

</Grid>
4

1 回答 1

3

这是由于本机 Android 滚动查看器(隐式嵌套在 Xaml 中ScrollViewer)之间的交互引起的,该查看器在接收焦点时尝试将元素滚动到视图中,而 则在第一次加载Button时获取焦点。Page

作为禁用此行为的解决方法,您可以使用以下BringIntoViewOnFocusChange属性:

    <ScrollViewer Grid.Row="1"
                  BringIntoViewOnFocusChange="False">
        <StackPanel>
            <TextBlock Text="Top"
                       VerticalAlignment="Top"
                       Height="500" />
            
            <TextBlock Text="Content"
                       FontSize="66"
                       Margin="0,0,0,300" />
            <Button Content="button"
                    Margin="0,0,0,300"/>

            <TextBlock Text="Bottom"
                       VerticalAlignment="Bottom" />
        </StackPanel>
    </ScrollViewer>
于 2020-09-24T09:27:58.017 回答