How to scroll to specific item in ListView using triggers

2.1k Views Asked by At

I am new to triggers concepts and I'm not able to get the right approach as to how to achieve it.

Based on data I have to scroll. Suppose data is cat so in list I have to 'scroll to cat'.

<ViewCell Height="80">
    <StackLayout Orientation="Horizontal" 
                 HorizontalOptions="FillAndExpand" 
                 VerticalOptions="FillAndExpand">
        <Label Text="{Binding Data}" 
               TextColor="White" 
               FontSize="45" 
               Margin="10,5,0,0" 
               HorizontalOptions="CenterAndExpand" 
               VerticalOptions="Center">
            <Label.Triggers>
                <DataTrigger TargetType="Label" 
                             Binding="{Binding Data}" 
                             Value="true">
                    <Setter Property="Text" 
                            Value="{Binding Data}" />
                </DataTrigger>
            </Label.Triggers>
        </Label>
    </StackLayout>
</ViewCell>
1

There are 1 best solutions below

0
On

Based on your comments... You want to scroll to specific item in your ListView. First thing you need to have is a reference to that specific object in your ItemSource list, after that using ScrollTo method you can scroll to that specific list item in your ListView.

You can try implement that like this:

 // targetObjectInListView = reference to some list item which you want to scroll to.
 YourListView.ScrollTo(targetObjectInListView , ScrollToPosition.Start, true);

More about ListView.ScrollTo you can find here.