Articles in this section
Category / Section

How to add a jump list with Xamarin.Forms ListView?

2 mins read

You can add jump list using Xamarin.Forms ListView by tapping on the indexed letter (group key) and scrolling to the respective group (GroupHeaderItemby passing group key index in the ScrollToIndex
method aslike contact list. This article explains you how to create jump list with group key and scroll to the tapped item.

Creates panel to shows the group key as indexed vertically.

<ContentPage xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms" >
    <ContentPage.Content>
       <Grid >
          <syncfusion:SfListView x:Name="listView" Grid.Row="0">
                <syncfusion:SfListView.ItemTemplate>
                          <DataTemplate>
                                     <ViewCell>
                                             <Grid>
                                                  <Image Source="{Binding ContactImage}" Grid.Column="0"/>
                                                        <StackLayout Orientation="Vertical" Grid.Column="1">
                                                                     <Label Text="{Binding ContactName}"/>
                                                                     <Label Text="{Binding ContactNumber}"/>
                                                        </StackLayout>
                                               </Grid>
                                             <StackLayout HeightRequest="1" BackgroundColor="LightGray"/>
                                     </ViewCell>
                          </DataTemplate>
                </syncfusion:SfListView.ItemTemplate>                
            </syncfusion:SfListView>
            <Grid x:Name="IndexPanelGrid" Grid.Row="0"  VerticalOptions="CenterAndExpand" HorizontalOptions="End" />
         </Grid>
    </ContentPage.Content>
</ContentPage>

 

Creates and populates the index panel with index labeled from the Group key.

ListView.Loaded += ListView_Loaded;
 
private void ListView_Loaded(object sender, ListViewLoadedEventArgs e)
{
     var groupcount = this.ListView.DataSource.Groups.Count;
     for (int i = 0; i < groupcount; i++)
     {
        label = new Label();  
        GroupResult group = ListView.DataSource.Groups[i];
        label.Text = group.Key.ToString();
        indexPanelGrid.Children.Add(label, 0, i);
        var labelTapped = new TapGestureRecognizer() { Command = new Command<object>(OnTapped), CommandParameter = label };
        label.GestureRecognizers.Add(labelTapped);
     }
}

 

ByOn tapping the group key value loaded in the index panel, you can scroll the listview to the respective group by comparing all GroupHeader’s Key values as follows.like below.

private void OnTapped(object obj)
{
    if (previousLabel != null)
    {
      previousLabel.TextColor = Color.DimGray;
    }
    var label = obj as Label;
    var text = label.Text;
    label.TextColor = Color.Red;
    for (int i = 0; i < ListView.DataSource.Groups.Count; i++)
    {
        var group = ListView.DataSource.Groups[i];
 
        if (group.Key == null)
          App.Current.MainPage.DisplayAlert("Message", "Group not available", "ok");
        if ((group.Key != null && group.Key.Equals(text)))
        {
                  ListView.LayoutManager.ScrollToRowIndex (ListView.DataSource.DisplayItems.IndexOf(group), true);
         }
     }
     previousLabel = label;
}

 

OutpPut

Jump List

Download the sample from GitHub.

 

Conclusion

I hope you enjoyed learning about how to add a jump list with Xamarin.Forms ListView.

You can refer to our Xamarin.Forms ListView feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied