Change Checkbox state on tapping of list view

Hello! 

I am currently using SfCheckBox inside a normal xamarin.forms listview. 

My problem is that the state of the checkbox is only toggled when the text or the checkbox itself are clicked. I would like to change the state of it also when the list item is clicked/tapped. 

Something similar to what happens with the <Label from="id"></Label> and <input type="checkbox" id=""/> that can be used on the web. 

I am currently trying to use the "ItemTapped" of the listview, but I am not being able to access the correct sfcheckbox from that context. 

Hope someone can help me!

Thanks in advance!

Cheers!

3 Replies 1 reply marked as answer

YP Yuvaraj Palanisamy Syncfusion Team September 2, 2020 04:13 PM UTC

Hi Bruno Canto Porto 
   
Greetings from Syncfusion.  
  
Your requirement has been achieved by changing the IsChecked property of SfCheckBox on the ListView ItemTapped event with enabling the InputTransparent 
  
Code Snippet  
XAML:  
   
<ListView Margin="15, 5"  
          SelectionMode="None"  
          HorizontalOptions="FillAndExpand"  
          VerticalOptions="FillAndExpand"  
          ItemTapped="ListView_ItemTapped"  
          ItemsSource="{Binding SelectedItems}">  
    <ListView.ItemTemplate>  
   
       . . .  
   
         <sfButtons:SfCheckBox x:Name="selectCheckBox"  
                  InputTransparent="True"  
                  IsChecked="{Binding IsSelected, Mode=TwoWay}"  
                  HorizontalOptions="FillAndExpand"  
                  VerticalOptions="Center">  
        </sfButtons:SfCheckBox>  
   
. . .  
</ ListView>  
   
 
   
   
C#  
private void ListView_ItemTapped(object sender, ItemTappedEventArgs e)  
 
    var item = e.Item as Model;  
    if (item != null)  
    {  
        item.IsSelected = !item.IsSelected;  
    }  
 
 
   
   
Also, we have attached the sample for your reference. Please find the sample from the below link.  
 
  
Regards, 
Yuvaraj 
  


Marked as answer

BC Bruno Canto Porto September 2, 2020 08:25 PM UTC

Hello Yuvaraj,

It worked like a charm! 

The sample was simply perfect. 

Thank you very much!

Regards,
Bruno


RS Ramya Soundar Rajan Syncfusion Team September 3, 2020 06:04 AM UTC

Hi Bruno Canto Porto 
 
Thanks for your update.  
  
Please let us know if you would require any further assistance. 
 
Regards, 
Ramya S

Loader.
Up arrow icon