c# - 为什么我的屏蔽条目不会更新但其他所有内容都会更新(xamarin.forms.MaskedEntry 控件)
问题描述
目前我正在从具有 MaskedEntry 的表单中保存数据,第一次保存它是可行的。我的问题是,当我单击详细信息页面并尝试更新它时,所有内容都会更新,但不是我的 MaskedEntry。在此之前,我尝试不使用 MaskedEntry 并且它正在工作。
在 调试器中,await App.Database.UpdateTasksAsync(task);
您可以看到除了作为 MaskedEntry 的 TaskDuration 之外的一切都发生了变化。
在此之前,我使用它而不是 MaskedEntry,我没有问题,但它当然没有被屏蔽。
<Entry x:Name="TaskDuration" Placeholder="HH:MM:SS" Text="{Binding TaskDuration}"/>
注意:我已经有许多 TasksGroup 和 Tasks 条目,它们都可以工作,但更新后的 Tasks 的 MaskedEntry 除外。
我用过:https ://github.com/TBertuzzi/Xamarin.Forms.MaskedEntry
感谢帮助。
1.从NewTasksGroupPage.xaml填写初始表单(这个保存一次就可以了)
//other entry fields
<StackLayout>
<Label Text="Durée quotidienne" FontAttributes="Bold" FontFamily="ROBOTO" TextColor="#000000"></Label>
<control:MaskedEntry Placeholder="HH:MM:SS" Mask="XX:XX:XX" Keyboard="Numeric" Text="{Binding TaskDuration}"></control:MaskedEntry>
<Label Text="{Binding ErrorMessages[TaskDuration]}" TextColor="#FF0000" FontAttributes="Bold"></Label>
</StackLayout>
2.在NewTaskPageViewModel.cs中保存初始表单
async Task SaveNewTask()
{
IsBusy = true;
await Task.Delay(4000);
IsBusy = false;
TasksGroup tasksGroup = new TasksGroup();
Tasks tasks = new Tasks();
tasksGroup.TasksGroupDescription = TasksGroupDescription;
tasksGroup.TasksGroupDate = TasksGroupDate;
tasks.TaskDuration = TaskDuration;
tasks.TaskDBA = TaskDBA;
tasks.TaskDescription = TaskDescription;
tasksGroup.Taches = new List<Tasks>() { tasks };
if(ValidateTasksGroup(tasksGroup) && ValidateTasks(tasks))
{
await App.Database.SaveTasksGroupAsync(tasksGroup);
//tasks.TasksGroupID = tasksGroup.ID;
//await App.Database.AddTaskAsync(tasks);
await Application.Current.MainPage.DisplayAlert("Save", "La tâche a été enregistrée", "OK");
await Application.Current.MainPage.Navigation.PopAsync();
NotifyPropertyChanged();
}
}
3. 编辑 TasksDetailsPage.xaml 中的条目(即不更新的条目)
//other entries
<StackLayout>
<Label Text="Durée quotidienne" FontAttributes="Bold" FontFamily="ROBOTO" TextColor="#000000"></Label>
<control:MaskedEntry Placeholder="HH:MM:SS" Mask="XX:XX:XX" Keyboard="Numeric" Text="{Binding TaskDuration}"></control:MaskedEntry>
<Label Text="{Binding ErrorMessages[TaskDuration]}" TextColor="#FF0000" FontAttributes="Bold"></Label>
</StackLayout>
4. 从 TasksDetailsPageViewModel.cs 更新详情页
async Task UpdateTask(TasksGroup tasksGroup, Tasks task)
{
if (ValidateTasksGroup(tasksGroup) && ValidateTasks(task))
{
bool isUserAccept = await Application.Current.MainPage.DisplayAlert("Update", "Voulez-vous vraiment modifier les informations", "OK", "Cancel");
if (isUserAccept)
{
await App.Database.UpdateTasksGroupAsync(tasksGroup);
await App.Database.UpdateTasksAsync(task);
}
await Application.Current.MainPage.Navigation.PopAsync();
NotifyPropertyChanged();
}
}
解决方案
推荐阅读
- string - 如何通过字符串而不是数组来实现 Yii2 关系?
- android - 无法删除本地数据库 CouchBase lite 中的文档
- wpf - 从 Api 获取 JSON - WPF 应用程序
- magento2 - Magento 2:如何插入含税价格?
- matlab - 我可以在 Matlab 中写出包含不同维度数据的 txt 或 csv 文档吗?
- java - 如何以编程方式更改设备显示屏的刷新率?
- amazon-web-services - DevOps - CloudFront/Lambda 将某些路径路由到某些服务器
- spring-boot - 在spring boot application.properties/.yml中根据OS设置日志文件位置
- java - Spring REST API 中自定义接受/标头和返回类型的 406 HTTP 状态
- python - 在 Pandas 中读取带逗号的 CSV 文件时出现问题