We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

EventToCommandBehavior with SfListView ItemTapped and CommandParameter

Thread ID:





132046 Aug 9,2017 01:54 PM UTC Aug 10,2017 03:15 PM UTC Xamarin.Forms 1
Tags: SfListView
Christoph Nienaber
Asked On August 9, 2017 01:54 PM UTC

I have the following:
A SfListView with an Image and a Label as cells on a xaml page, utilizing MVVM. I want to use the EventToCommandBehavior (https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/behaviors/reusable/event-to-command-behavior/) to bind the ItemTapped event to a command. As commandparameter I want to pass a property of an object inside the SfListView Source ObservableCollection. 

Heres my xaml: 

        <vm:SiteOverviewViewModel x:Name="viewModel" />
            <conv:ByteToImageSourceConverter x:Key="ByteConverter" />
    <ContentView ControlTemplate="{StaticResource MainPageTemplate}">
            <syncfusion:SfListView ItemSize="300" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"
                                       ItemsSource="{Binding Sites}" Orientation="Vertical">
                    <behaviors:EventToCommandBehavior EventName="ItemTapped" Command="{Binding Path=BindingContext.SiteClickCommand}" CommandParameter="{Binding Name}" />
                        <Grid Padding="10">
                                <RowDefinition Height="0.75*" />
                                <RowDefinition Height="0.25*" />
                            <Image Source="{Binding ImageData, Converter={StaticResource ByteConverter}}"
                                       HorizontalOptions="Center" />
                            <Button Text="{Binding FriendlyName}"
                                    Command="{Binding Path=BindingContext.SiteClickCommand,
                                    Source={x:Reference View}}" CommandParameter="{Binding Name}" FontSize="Large" />

So basically I want the ItemTapped event to behave exactly as the button does, so that I can exchange the button with a label, having both the image and the label be clickable as a result. 
However my button works and the ItemTapped-Command does not work. Notice the ControlTemplate that makes the xaml a bit harder. How can I solve this issue while maintaining MVVM?

Muthu Kumaran Gnanavinayagam [Syncfusion]
Replied On August 10, 2017 03:15 PM UTC

Hi Christoph, 
You can achieve your requirementEvents into Commands using Behaviors in SfListView by creating a Command for ItemTapped event of SfListView in ViewModel. You can associate the Commands to Events of SfListView using Behaviors. We have published a KB documentation to meet your requirement. Please refer the attached KB link for more information. 
Please let us know if you require further assistance. 
G.Muthu Kumaran. 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon