Skip to content

Commit a83edc6

Browse files
authored
Readme file updated
1 parent f3be90c commit a83edc6

File tree

1 file changed

+96
-2
lines changed

1 file changed

+96
-2
lines changed

README.md

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,96 @@
1-
# hide-line-separator-listview-xamarin
2-
How to hide the line separator in Xamarin.Forms ListView with grouping (SfListView)
1+
# How to hide the line separator in Xamarin.Forms ListView with grouping (SfListView)
2+
3+
The Xamarin.Forms [SfListView](https://help.syncfusion.com/xamarin/listview/overview) does not contain line separator by default. You can load the StackLayout with height as 1 to separate the items.
4+
5+
You can hide the separator for any item in a group by changing the [IsVisible](https://docs.microsoft.com/en-us/dotnet/api/xamarin.forms.visualelement.isvisible) property of the **StackLayout** (Used as a Separator) loaded in the [SfListView.ItemTemplate](https://help.syncfusion.com/cr/cref_files/xamarin/Syncfusion.SfListView.XForms~Syncfusion.ListView.XForms.SfListView~ItemTemplate.html).
6+
7+
**XAML**
8+
9+
Converter bind to **Separator** to hide it based on the requirement.
10+
11+
``` xml
12+
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
13+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
14+
xmlns:local="clr-namespace:ListViewXamarin"
15+
xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms"
16+
x:Class="ListViewXamarin.MainPage" Padding="0,50,0,0">
17+
<ContentPage.Resources>
18+
<ResourceDictionary>
19+
<local:VisibilityConverter x:Key="VisibilityConverter"/>
20+
</ResourceDictionary>
21+
</ContentPage.Resources>
22+
<ContentPage.Content>
23+
<StackLayout>
24+
<syncfusion:SfListView x:Name="listView" ItemSize="60" ItemsSource="{Binding ContactsInfo}">
25+
<syncfusion:SfListView.ItemTemplate >
26+
<DataTemplate>
27+
<StackLayout>
28+
<StackLayout IsVisible="{Binding .,Converter={StaticResource VisibilityConverter}, ConverterParameter={x:Reference Name=listView}}" BackgroundColor="Red" HeightRequest="1"/>
29+
<Grid>
30+
<Grid.ColumnDefinitions>
31+
<ColumnDefinition Width="70" />
32+
<ColumnDefinition Width="*" />
33+
</Grid.ColumnDefinitions>
34+
<Image Source="{Binding ContactImage}" VerticalOptions="Center" HorizontalOptions="Center" HeightRequest="50" WidthRequest="50"/>
35+
<Grid Grid.Column="1" RowSpacing="1" Padding="10,0,0,0" VerticalOptions="Center">
36+
<Label LineBreakMode="NoWrap" TextColor="#474747" Text="{Binding ContactName}"/>
37+
<Label Grid.Row="1" Grid.Column="0" TextColor="#474747" LineBreakMode="NoWrap" Text="{Binding ContactNumber}"/>
38+
</Grid>
39+
</Grid>
40+
</StackLayout>
41+
</DataTemplate>
42+
</syncfusion:SfListView.ItemTemplate>
43+
<syncfusion:SfListView.GroupHeaderTemplate>
44+
<DataTemplate>
45+
<StackLayout BackgroundColor="#E4E4E4">
46+
<Label Text="{Binding Key}" FontSize="22" FontAttributes="Bold" VerticalOptions="CenterAndExpand" HorizontalOptions="Start" Margin="20,0,0,0" />
47+
</StackLayout>
48+
</DataTemplate>
49+
</syncfusion:SfListView.GroupHeaderTemplate>
50+
</syncfusion:SfListView>
51+
</StackLayout>
52+
</ContentPage.Content>
53+
</ContentPage>
54+
```
55+
56+
**C#**
57+
58+
In the converter, get the group result value and change the visibility of the element of first item in a group.
59+
60+
``` c#
61+
public class VisibilityConverter : IValueConverter
62+
{
63+
SfListView ListView;
64+
65+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
66+
{
67+
ListView = parameter as SfListView;
68+
69+
if (value == null || ListView.DataSource.Groups.Count == 0)
70+
return false;
71+
72+
var groupresult = GetGroup(value);
73+
var list = groupresult.Items.ToList<object>().ToList();
74+
return list[0] != value;
75+
}
76+
77+
private GroupResult GetGroup(object itemData)
78+
{
79+
GroupResult itemGroup = null;
80+
81+
foreach (var item in this.ListView.DataSource.DisplayItems)
82+
{
83+
if (item == itemData)
84+
break;
85+
86+
if (item is GroupResult)
87+
itemGroup = item as GroupResult;
88+
}
89+
return itemGroup;
90+
}
91+
}
92+
```
93+
94+
**Output**
95+
96+
![HideLineSeparator](https://github.com/SyncfusionExamples/hide-line-separator-listview-xamarin/blob/master/ScreenShot/HideLineSeparator.png)

0 commit comments

Comments
 (0)