<ContentPage.Resources>
<ResourceDictionary>
<local:GroupHeaderConvertor x:Key="TemplateConverter"/>
</ResourceDictionary>
</ContentPage.Resources>
…
<listView:SfListView x:Name="listView" ItemsSource="{Binding contactsinfo}">
<listView:SfListView.GroupHeaderTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout BackgroundColor="#E4E4E4" Margin="{Binding Level,Converter={StaticResource TemplateConverter}}">
<Label Text="{Binding Key}" FontSize="22" FontAttributes="Bold" VerticalOptions="Center"
HorizontalOptions="Start" Margin="20,0,0,0" />
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</listView:SfListView.GroupHeaderTemplate> |
public class GroupHeaderConvertor : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((int)value == 1)
return new Thickness(5, 5, 5, 0);
else
return new Thickness((int)value * 15, 5, 5, 0);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |