lundi 8 juin 2020

Toggle CheckBox inside a ViewCell in Xmarin.Forms

I would like to know how to toggle the current checkbox inside my ListView - ViewCell on item tapped event.

<ListView x:Name="listViewCities"
                      ItemSelected="ListViewCities_ItemSelected"
                      ItemTapped="ListViewCities_ItemTapped">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout Orientation="Horizontal">
                    <CheckBox x:Name="chkSelectedCity" />
                    <Label Text="{Binding Name}" 
                                       FontSize="Medium"
                                       VerticalOptions="CenterAndExpand" />
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Here is my item tapped event.

private void ListViewCities_ItemTapped(object sender, ItemTappedEventArgs e)
{
    //Here i want to toggle the current check box as true
    //something like chkSelectedCity.checked = true;
}

Aucun commentaire:

Enregistrer un commentaire