Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Using CheckBox in ListView

$
0
0

I've got the problem that I don't know how to use the new CheckBox element within a ListView. The only thing I've found is how to use a button within it.
Maybe someone already knows how to do this.
Edit: I know how to add the element itself but not how to sync this with my database. I want to change the boolean Completed once the CheckBox is clicked.

Here is the xmal part:
ListView x:Name="ToDoListView" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" HasUnevenRows="true" ItemSelected="ToDoListView_ItemSelected"> <ListView.ItemTemplate> <DataTemplate> <ViewCell> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="7*"/> <ColumnDefinition Width="2*"/> </Grid.ColumnDefinitions> <BoxView CornerRadius="2" BackgroundColor="#494949" Grid.Column="0" Grid.ColumnSpan="3"/> <CheckBox Grid.Column="0" IsChecked="{Binding Completed}" CheckedChanged="CheckBox_CheckedChanged"/> <StackLayout Grid.Column="1"> <Label Text="{Binding Subject}" TextColor="White" FontSize="16" LineBreakMode="NoWrap" /> <Label Text="{Binding Assignment}" TextColor="White" FontSize="13" /> </StackLayout> <StackLayout Grid.Column="2" VerticalOptions="EndAndExpand" HorizontalOptions="EndAndExpand"> <Label Text="{Binding Deadline, StringFormat='{0:dd/MM/yyyy}'}" TextColor="White" FontSize="10"/> </StackLayout> </Grid> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView>
and here the code behind:
`private void CheckBox_CheckedChanged(object sender, CheckedChangedEventArgs args)
{
var todo = (ToDo)BindingContext;
Console.WriteLine(todo + " " + (ToDo)BindingContext);
if(todo != null)
{
if(todo.Completed==false)
{
todo.Completed = true;
}
else
{
todo.Completed = false;
}

        }`

Sorry for the mess with using the Code formation in the Forum.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>