我怎样才能阻止 Android ScrollViewer 滚动到它的第一个按钮 child
How can I stop Android ScrollViewer to scroll itself to its first button child
我有一个非常简单的页面,其中包含页眉、页脚和可滚动的内容。我的 iOS 和 UWP 应用似乎运行良好。当我进入页面 iOS 并且 UWP 开始时 ScrollView 在顶部滚动,但是 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>
这是由本机 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>
我有一个非常简单的页面,其中包含页眉、页脚和可滚动的内容。我的 iOS 和 UWP 应用似乎运行良好。当我进入页面 iOS 并且 UWP 开始时 ScrollView 在顶部滚动,但是 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>
这是由本机 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>