【发布时间】:2020-11-24 02:51:45
【问题描述】:
我有一个垂直列表视图,它的项目模板中有另一个水平位置的列表视图,现在一切正常,但如果其中一个滚动,我希望能够滚动所有这些子列表视图。
现在我希望所有行中的所有子列表视图一起滚动。 我该怎么做?!
也许我可以为具有可绑定属性的列表视图创建一个扩展类以进行滚动?! 像这样的:
public class ScrollableListView : ListView {
public static readonly BindableProperty ScrollProperty = BindableProperty.Create("ScrollPosition", typeof(double), typeof(ScrollableListView));
public double ScrollPosition
{
get { return (double)GetValue(ScrollProperty ); }
set
{
SetValue(ScrollProperty, value);
ScrollToAsync(0, value);
}
}
}
然后在 xaml 中将所有 ScrollPosition 属性绑定到一个变量,该变量会在列表滚动时更改,如下所示:
<DataTemplate>
<RelativeLayout HeightRequest="{Binding Width}" Margin="{Binding Margin}">
<Grid Rotation="90" AnchorX="0" AnchorY="0"
RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height}"
RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}">
<Local:ScrollableListView ScrollPosition="{Binding SPos}" Scrolled="Generic_Scroll_Event"/>
</Grid>
</RelativeLayout>
</DataTemplate>
并且在Generic_Scroll_EventSPos变量中改变了事件发送者的位置。
这只是我脑海中突然出现的东西......无论如何,任何帮助都表示感谢^^。
【问题讨论】:
-
您能提供一份您在这里尝试过的样品吗?我将尝试重现您的问题并尝试给出一种解决方案。
-
好吧,我试过了,但是
ScrollTo函数没有占据位置 -_- 而是一个要滚动到的项目... -
请在github上提供一个简单的示例,我会下载你的示例进行测试,并尝试给出一个解决方案。
-
没有样本...我没有什么要测试的...我不是在寻找解决方案,我在寻找一个想法或一些解决方法来完成这项工作,这正在制作多个列表视图一起滚动。
-
如果您不提供简单的示例,我将无法重现您的问题。
标签: listview xamarin xamarin.forms scroll