2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
You can add jump list using Xamarin.Forms ListView by tapping on the indexed letter (group key) and scrolling to the respective group (GroupHeaderItem) by 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 Download the sample from GitHub.
|
2X faster development
The ultimate Xamarin UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.