单击任何子元素时,Xamarin Forms ScrollView 会自动滚动到开头

问题描述

我在 Xamarin Forms 中创建了一个水平/垂直滚动视图,其中包含多种类型的子项,例如:

enter image description here

这是我的代码

ScrollView scrollTracks = new ScrollView
{
     BackgroundColor = Color.Black,VerticalOptions = Layoutoptions.StartAndExpand,HorizontalOptions = Layoutoptions.FillAndExpand,Content = layoutTracks,Orientation = ScrollOrientation.Both
};

当我单击某些子元素(例如 CustomCheckBoxes、标签或 ImageViews)时,程序会自动将视图滚动到开头。

我在 UWP 平台上对此进行了测试。

我怎样才能让程序停止这样做?

解决方法

将此标签添加到 ScrollView 解决了我的问题:

IsTabStop = false

代码如下:

ScrollView scrollTracks = new ScrollView
{
     BackgroundColor = Color.Black,VerticalOptions = LayoutOptions.StartAndExpand,HorizontalOptions = LayoutOptions.FillAndExpand,Content = layoutTracks,Orientation = ScrollOrientation.Both,IsTabStop = false
};