复选框待办事项列表更新 SQLite 数据库 Xamarin / .net Maui
Checkbox To Do list update SQLite database Xamarin / .net Maui
我正在尝试让一个复选框与 SQLite 一起工作,当检查完成时它将更新任务模型中的完成 属性。该复选框位于 collectionview 中,其中 itemsource 设置为任务列表。使用 sqlite-net-pcl
XAML 元素:
<CheckBox x:Name="CheckBox_Done" IsChecked="{Binding Done}" CheckedChanged="CheckedDone" />
后面的 C# 代码:
private async void CheckedDone(object sender, CheckedChangedEventArgs e)
{
var temp = sender as Tasks;
temp.Done = !temp.Done;
await App.Database.UpdateTask(temp);
}
我的数据库更新功能
public Task<int> UpdateTask(Tasks task)
{
return db.UpdateAsync(task);
}
作为任务的发件人似乎没有工作,我在这里做错了什么>?
sender
是引发事件
的控件
private async void CheckedDone(object sender, CheckedChangedEventArgs e)
{
// get the sender
var cb = sender as CheckBox;
// use the BindingContext to get the bound Task
var task = cb.BindingContext as Tasks;
// task should already reflect the updated Value, no need
// to change it again
await App.Database.UpdateTask(task);
}
我正在尝试让一个复选框与 SQLite 一起工作,当检查完成时它将更新任务模型中的完成 属性。该复选框位于 collectionview 中,其中 itemsource 设置为任务列表。使用 sqlite-net-pcl
XAML 元素:
<CheckBox x:Name="CheckBox_Done" IsChecked="{Binding Done}" CheckedChanged="CheckedDone" />
后面的 C# 代码:
private async void CheckedDone(object sender, CheckedChangedEventArgs e)
{
var temp = sender as Tasks;
temp.Done = !temp.Done;
await App.Database.UpdateTask(temp);
}
我的数据库更新功能
public Task<int> UpdateTask(Tasks task)
{
return db.UpdateAsync(task);
}
作为任务的发件人似乎没有工作,我在这里做错了什么>?
sender
是引发事件
private async void CheckedDone(object sender, CheckedChangedEventArgs e)
{
// get the sender
var cb = sender as CheckBox;
// use the BindingContext to get the bound Task
var task = cb.BindingContext as Tasks;
// task should already reflect the updated Value, no need
// to change it again
await App.Database.UpdateTask(task);
}