Thread ID: |
Created: |
Updated: |
Platform: |
Replies: |
143005 | Feb 28,2019 10:39 AM UTC | Mar 15,2019 10:44 AM UTC | Xamarin.Forms | 7 |
![]() |
Tags: SfListView |
Xaml
<syncfusion:SfListView AllowGroupExpandCollapse="True"
ItemsSource="{Binding contactsinfo}">
<syncfusion:SfListView.GroupHeaderTemplate>
<DataTemplate>
<Grid >
<Grid.ColumnDefinitions>
<Image Source="{Binding IsExpand, Converter={StaticResource BoolToImageConverter}}"/>
</StackLayout>
</Grid>
</DataTemplate>
</syncfusion:SfListView.GroupHeaderTemplate>
</syncfusion:SfListView>
Converter
public class BoolToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value)
{
return ImageSource.FromResource("SfListViewSample.Images.GroupExpand.png");
}
else
{
return ImageSource.FromResource("SfListViewSample.Images.GroupCollapse.png");
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
Xaml
<syncfusion:SfListView AllowGroupExpandCollapse="True" ItemsSource="{Binding contactsinfo}">
<syncfusion:SfListView.GroupHeaderTemplate>
<DataTemplate>
<Grid BackgroundColor="#E4E4E4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackLayout Orientation="Horizontal" HorizontalOptions="Start" VerticalOptions="Center" Padding="10,0,0,0">
<Label Text="{Binding Key}" TextColor="Black" FontSize="Medium"/>
</StackLayout>
<StackLayout Orientation="Horizontal" Grid.Column="1" Padding="0,0,20,0"
HorizontalOptions="EndAndExpand" VerticalOptions="Center">
<Label Text="{Binding Count}" TextColor="Black" FontSize="Medium"/>
<Label Text="Item(s)" TextColor="Black" FontSize="Medium"/>
<Image Source="{Binding Items, Converter={StaticResource BoolToImageConverter}}" HeightRequest="50" WidthRequest="100"/>
</StackLayout>
</Grid>
</DataTemplate>
</syncfusion:SfListView.GroupHeaderTemplate>
</syncfusion:SfListView>
Converter
public class BoolToImageConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var image = ImageSource.FromResource("SfListViewSample.Images.GroupExpand.png");
var items = value as IEnumerable;
if (items != null)
{
var groupitems = items.ToList<object>().ToList<object>();
if (groupitems != null)
{
for (int i = 0; i < groupitems.Count; i++)
{
var contact = groupitems[i] as Contacts;
if (contact.ContactName == "Kenny")
image = ImageSource.FromResource("SfListViewSample.Images.new.jpg");
}
}
}
return image;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
} |
This post will be permanently deleted. Are you sure you want to continue?
Sorry, An error occured while processing your request. Please try again later.
This page will automatically be redirected to the sign-in page in 10 seconds.