首页 > 解决方案 > 为什么我的屏蔽条目不会更新但其他所有内容都会更新(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();
    }
}

标签: c#xamarinxamarin.forms

解决方案


推荐阅读