xmlns:sflistview="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms"
xmlns:syncfusion="clr-namespace:Syncfusion.XForms.Accordion;assembly=Syncfusion.Expander.XForms">
<syncfusion:SfAccordion x:Name="Accordion" ExpandMode="SingleOrNone" BindableLayout.ItemsSource="{Binding EmployeeInfo}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<syncfusion:AccordionItem>
<syncfusion:AccordionItem.Header>
<Grid HeightRequest="50">
<Label Text="{Binding EmployeeName}"/>
</Grid>
</syncfusion:AccordionItem.Header>
<syncfusion:AccordionItem.Content>
<Grid HeightRequest="160">
<sflistview:SfListView x:Name="listView"
BackgroundColor="Beige" IsScrollingEnabled="False"
ItemsSource="{Binding Customers}">
<sflistview:SfListView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding CustomerName}"/>
</DataTemplate>
</sflistview:SfListView.ItemTemplate>
</sflistview:SfListView>
</Grid>
</syncfusion:AccordionItem.Content>
</syncfusion:AccordionItem>
</DataTemplate>
</BindableLayout.ItemTemplate>
</syncfusion:SfAccordion> |
xmlns:local="clr-namespace:GettingStarted"
xmlns:sflistview="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms"
<sflistview:SfListView x:Name="OuterListView"
ItemsSource="{Binding EmployeeInfo}"
AutoFitMode="DynamicHeight"
AllowGroupExpandCollapse="True">
<sflistview:SfListView.GroupHeaderTemplate>
<DataTemplate>
<Label Text="{Binding Key}" HeightRequest="50" BackgroundColor="LightCyan"/>
</DataTemplate>
</sflistview:SfListView.GroupHeaderTemplate>
<sflistview:SfListView.DataSource>
<data:DataSource>
<data:DataSource.GroupDescriptors>
<data:GroupDescriptor PropertyName="EmployeeName"/>
</data:DataSource.GroupDescriptors>
</data:DataSource>
</sflistview:SfListView.DataSource>
<sflistview:SfListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid>
<local:ExtendedListView x:Name="InnerListView"
BackgroundColor="LightPink"
HeightRequest="{Binding InnerListHeight}"
ItemSize="50"
ItemsSource="{Binding Customers}">
<local:ExtendedListView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding CustomerName}"/>
</DataTemplate>
</local:ExtendedListView.ItemTemplate>
</local:ExtendedListView>
</Grid>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</sflistview:SfListView.ItemTemplate>
</sflistview:SfListView> |
public class ExtendedListView : SfListView
{
VisualContainer container;
public ExtendedListView()
{
container = this.GetVisualContainer();
this.Loaded += ExtendedListView_Loaded;
}
private void ExtendedListView_Loaded(object sender, ListViewLoadedEventArgs e)
{
var extent = (double)container.GetType().GetRuntimeProperties().FirstOrDefault(x =>
x.Name == "TotalExtent").GetValue(container);
this.HeightRequest = extent;
(this.BindingContext as Employee).InnerListHeight = extent;
}
} |
<sflistview:SfListView.GroupHeaderTemplate>
<DataTemplate>
<Grid HeightRequest="50" BackgroundColor="Aquamarine">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="{Binding Key}"
FontSize="18"
FontAttributes="Bold"
VerticalOptions="Center"
HorizontalOptions="Start"
Margin="20,0,0,0" />
<Label Text="{Binding Key, Converter={StaticResource phoneNumberConverter}, ConverterParameter={x:Reference OuterListView}}"
Grid.Column="1"
FontSize="18"
HorizontalOptions="Start"
VerticalOptions="Center"/>
<Label Text="{Binding Key, Converter={StaticResource addressConverter}, ConverterParameter={x:Reference OuterListView}}"
Grid.Column="2"
FontSize="18"
VerticalOptions="Center"
HorizontalOptions="Start"
Margin="0,0,0,0"/>
</Grid>
</DataTemplate>
</sflistview:SfListView.GroupHeaderTemplate> |
class AddressConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return null;
var bindingContext = (parameter as SfListView).BindingContext as ViewModel;
var model = bindingContext.EmployeeInfo;
foreach (var item in model)
{
if ((string)value == item.EmployeeName)
{
return item.Address;
}
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
Hi Hassan,Thank you for the update.We have checked the reported query “Customizing GroupHeader in ListView” from our end. We would like to let you know that ListView allows you to customize GroupHeader using GroupHeaderTemplate with good performance. Please refer the following code snippets for more reference,Code Snippet XAML : Customizing GroupHeader in ListView
<sflistview:SfListView.GroupHeaderTemplate><DataTemplate><Grid HeightRequest="50" BackgroundColor="Aquamarine"><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="*"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><Label Text="{Binding Key}"FontSize="18"FontAttributes="Bold"VerticalOptions="Center"HorizontalOptions="Start"Margin="20,0,0,0" /><Label Text="{Binding Key, Converter={StaticResource phoneNumberConverter}, ConverterParameter={x:Reference OuterListView}}"Grid.Column="1"FontSize="18"HorizontalOptions="Start"VerticalOptions="Center"/><Label Text="{Binding Key, Converter={StaticResource addressConverter}, ConverterParameter={x:Reference OuterListView}}"Grid.Column="2"FontSize="18"VerticalOptions="Center"HorizontalOptions="Start"Margin="0,0,0,0"/></Grid></DataTemplate></sflistview:SfListView.GroupHeaderTemplate>Code Snippet C# : Converter class for customizing GroupHeader
class AddressConverter : IValueConverter{public object Convert(object value, Type targetType, object parameter, CultureInfo culture){if (value == null)return null;var bindingContext = (parameter as SfListView).BindingContext as ViewModel;var model = bindingContext.EmployeeInfo;foreach (var item in model){if ((string)value == item.EmployeeName){return item.Address;}}return null;}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){throw new NotImplementedException();}}We have prepared a sample based on your requirement and you can download the same from the following link,Sample Link : SfListViewSamplePlease let us know, if you would require further assistance.Regards,Chandrasekar Sampathkumar