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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Sflistview -Set the Bindingcontext for command and command parameter in a listview item

Thread ID:





144873 May 27,2019 10:25 AM UTC May 28,2019 01:55 PM UTC Xamarin.Forms 1
Tags: SfListView
Asked On May 27, 2019 10:28 AM UTC

I am using sflistview to display list of items (uses samplelistviewmodel)  and having a datatemplate for my viewcell (uses sampleitemviewmodel)  .
Inside the view cell i have a grid , with a Tap gesture recoognizer .This recognizer would call a command from a samplelistviewmodel and pass the sampleitemviewmodel as a Commandparameter to that command .

                    ItemsSource="{Binding ItemList}"
 SampleViewCell />

My code snippet is as follows,

  <ViewCell.View >  

                            Command="{Binding Source={x:Reference SampleViewCell}, Path=Parent.BindingContext.SampleCommand}"
                            CommandParameter="{Binding Source={x:Reference SampleViewCell}, Path=BindingContext}"
  ViewCell.View >

However the same works , when i try with listview it works , while with sflitview it doesnt.Please help

Subburaj Pandian Veluchamy [Syncfusion]
Replied On May 28, 2019 01:55 PM UTC

Hi Ramya, 
Thank you for contacting Syncfusion support. 
We would like to inform you that in SfListView, BindingContext of the ItemTemplate will be Model class for the Template items. So, when you define the Command for ViewCell, it is necessary to initialize the command in Model as following.  
public class MessageInfo : INotifyPropertyChanged 
       public Command<object> SampleCommand { get; } 
       public MessageInfo() 
            SampleCommand = new Command<object>(OnGridTapped); 
        private void OnGridTapped(object obj) 
            var param = obj as MessageInfo; 
            App.Current.MainPage.DisplayAlert("Message","Tapped Item :"+param.Text,"Ok"); 
<ViewCell > 
    <Grid ColumnSpacing="2" x:Name="Grid"> 
            <TapGestureRecognizer Command="{Binding Source={x:ReferenceGrid}, Path=BindingContext.SampleCommand}" CommandParameter="{Binding Source={x:Reference Grid}, Path=BindingContext}"/> 
</ViewCell > 
We have attached the model sample for your reference, 
Please let us know if you need any further assistance. 
Subburaj Pandian V 


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

Live Chat Icon For mobile
Live Chat Icon