问题
I'm having a vertical list view which has in its item template another list view in horizontal position, now everything works fine, but I want to be able to scroll all of these sub list views if one of them scrolled.
Here is an illustration:
Now I want all the sub list views in all rows to scroll together. How can I do this?!
Maybe I can make an extending class for the list view with bindable property for scrolling ?! Something like this:
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);
}
}
}
And then in xaml bind all ScrollPosition
property to a variable that changes whenever a list is scrolled, like this:
<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>
And in the Generic_Scroll_Event
The SPos
variable changes to the event sender's position.
This is just something that popped in my head ... Any help is appreciated anyway ^^.
回答1:
The above answer should work, but as there is no direct way of making a listview scroll to a position I had to make a workaround.
I used scrollviews instead and used it's template to work as a listview, then binded all of the scrollviews to the first one, in two way mode.
来源:https://stackoverflow.com/questions/64420241/how-to-make-multiple-list-views-scroll-together