How to hide line separator in Xamarin.Forms ListView with grouping?
The Xamarin.Forms ListView does not contain a line separator by default. You can load the StackLayout with a height of 1 to separate the items.
You can hide the separator for any item in a group by changing the IsVisible property of the StackLayout (Used as a Separator) loaded in the SfListView.ItemTemplate.
XAML
Converter binds to the Separator to hide it based on the requirement.
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:ListViewXamarin" xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms" x:Class="ListViewXamarin.MainPage" Padding="0,50,0,0"> <ContentPage.Resources> <ResourceDictionary> <local:VisibilityConverter x:Key="VisibilityConverter"/> </ResourceDictionary> </ContentPage.Resources> <ContentPage.Content> <StackLayout> <syncfusion:SfListView x:Name="listView" ItemSize="60" ItemsSource="{Binding ContactsInfo}"> <syncfusion:SfListView.ItemTemplate > <DataTemplate> <StackLayout> <StackLayout IsVisible="{Binding .,Converter={StaticResource VisibilityConverter}, ConverterParameter={x:Reference Name=listView}}" BackgroundColor="Red" HeightRequest="1"/> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="70" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Image Source="{Binding ContactImage}" VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="50" WidthRequest="50"/> <Grid Grid.Column="1" RowSpacing="1" Padding="10,0,0,0" VerticalOptions="Center"> <Label LineBreakMode="NoWrap" TextColor="#474747" Text="{Binding ContactName}"/> <Label Grid.Row="1" Grid.Column="0" TextColor="#474747" LineBreakMode="NoWrap" Text="{Binding ContactNumber}"/> </Grid> </Grid> </StackLayout> </DataTemplate> </syncfusion:SfListView.ItemTemplate> <syncfusion:SfListView.GroupHeaderTemplate> <DataTemplate> <StackLayout BackgroundColor="#E4E4E4"> <Label Text="{Binding Key}" FontSize="22" FontAttributes="Bold" VerticalOptions="CenterAndExpand" HorizontalOptions="Start" Margin="20,0,0,0" /> </StackLayout> </DataTemplate> </syncfusion:SfListView.GroupHeaderTemplate> </syncfusion:SfListView> </StackLayout> </ContentPage.Content> </ContentPage>
C#
In the converter, get the group result value and change the visibility of the first item in the group.
public class VisibilityConverter : IValueConverter { SfListView ListView; public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { ListView = parameter as SfListView; if (value == null || ListView.DataSource.Groups.Count == 0) return false; var groupresult = GetGroup(value); var list = groupresult.Items.ToList<object>().ToList(); return list[0] != value; } private GroupResult GetGroup(object itemData) { GroupResult itemGroup = null; foreach (var item in this.ListView.DataSource.DisplayItems) { if (item == itemData) break; if (item is GroupResult) itemGroup = item as GroupResult; } return itemGroup; } }
Output
Conclusion
I hope you enjoyed learning about how to hide line separator in Xamarin.Forms ListView with grouping.
You can refer to our Xamarin.Forms ListView feature tour page to know 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!