Changing image source on swipe based on items property

Hello,

In my sfListView, I am trying to change the image source for my right swipe template depending on what a property is for that item. Is this possible?

Thanks.

Ex.

For item 1 with the property isPaused == true, I want the picture in the swipe template to be a play icon
For item 2 with the property isPaused == false, I want the picture in the swipe template to be a pause icon

Thanks.

1 Reply 1 reply marked as answer

SS SaiGanesh Sakthivel Syncfusion Team February 4, 2021 02:06 PM UTC

Hi Spencer, 
 
Thank you for using syncfusion products. 
 
#Regarding Changing image source on swipe based on items property 
We would like to inform you that you can achieve your requirement with help of converter class in SfListview. Please refer to the following code snippet for your reference. 
 
In mainpage.xaml 
<syncfusion:SfListView.RightSwipeTemplate> 
    <DataTemplate> 
        <Grid> 
            <Grid BackgroundColor="#009EDA" HorizontalOptions="Fill" VerticalOptions="Fill" Grid.Column="0"> 
                <Grid VerticalOptions="Center" HorizontalOptions="Center"> 
                    <Image Grid.Column="0" 
                           Grid.Row="0" 
                           BackgroundColor="Transparent" 
                           HeightRequest="35" 
                           WidthRequest="35" 
                           Source="{Binding IsPaused,Converter={StaticResource converter}}" /> 
                </Grid> 
            </Grid> 
        </Grid> 
    </DataTemplate> 
</syncfusion:SfListView.RightSwipeTemplate> 
 
Inside the converter class, change the image source with help of bool value. 
public class Converter : IValueConverter 
{ 
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
    return (bool)value ? ImageSource.FromResource("ListViewXamarin.Images.pause.jpg") : ImageSource.FromResource("ListViewXamarin.Images.play.jpg"); 
} 
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
{ 
    throw new NotImplementedException(); 
} 
} 
 
Please refer to the tested sample in the following link for your reference. 
 
Please let us know if you have any concern. 
 
Regards, 
SaiGanesh Sakthivel 


Marked as answer
Loader.
Up arrow icon