示例#1
0
 public void OnNavigatedTo(INavigationParameters parameters)
 {
     if (parameters.GetNavigationMode() == NavigationMode.New)
     {
         MyTaskRepository fooMyTaskRepository = new MyTaskRepository();
         var fooTasks = fooMyTaskRepository.GetMyTask();
         foreach (var item in fooTasks)
         {
             MyTaskItemList.Add(new MyTaskItem
             {
                 MyTaskName   = item.MyTaskName,
                 MyTaskDate   = item.MyTaskDate,
                 MyTaskStatus = item.MyTaskStatus,
             });
         }
     }
     else
     {
         if (parameters.ContainsKey("Mode"))
         {
             string TaskMode  = parameters.GetValue <string>("Mode");
             var    fooObject = parameters.GetValue <MyTaskItem>("MyTaskItem");
             var    index     = MyTaskItemList.IndexOf(MyTaskItemList.FirstOrDefault(x => x.MyTaskName == fooObject.MyTaskName));
             if (TaskMode == "Update")
             {
                 MyTaskItemList[index] = fooObject;
             }
             else
             {
                 MyTaskItemList.RemoveAt(index);
             }
         }
     }
 }
示例#2
0
        public MainPageViewModel(INavigationService navigationService, IPageDialogService dialogService)
        {
            this.navigationService    = navigationService;
            this.dialogService        = dialogService;
            MyTaskItemSelectedCommand = new DelegateCommand(async() =>
            {
                //await _dialogService.DisplayAlertAsync("Info", $"你選取的是 {MyTaskItemSelected.MyTaskName}", "OK");

                NavigationParameters fooPara = new NavigationParameters();
                fooPara.Add("MyTaskItem", MyTaskItemSelected.Clone());
                fooPara.Add("Mode", "Edit");
                await navigationService.NavigateAsync("TaskDetailPage", fooPara);
            });

            AddCommand = new DelegateCommand(async() =>
            {
                NavigationParameters fooPara = new NavigationParameters();
                fooPara.Add("Mode", "Add");
                await navigationService.NavigateAsync("TaskDetailPage", fooPara);
            });

            MyTaskRefreshCommand = new DelegateCommand(() =>
            {
                RefreshIndex++;
                MyTaskItemList.Clear();
                MyTaskRepository fooMyTaskRepository = new MyTaskRepository();
                var fooTasks = fooMyTaskRepository.GetMyTask();
                foreach (var item in fooTasks)
                {
                    MyTaskItemList.Add(new MyTaskItem
                    {
                        MyTaskName   = $"{RefreshIndex} {item.MyTaskName}",
                        MyTaskDate   = item.MyTaskDate,
                        MyTaskStatus = item.MyTaskStatus,
                    });
                }
                RefreshingStatus = false;
            });

            DeleteCommand = new DelegateCommand <MyTaskItem>(x =>
            {
                var index = MyTaskItemList.IndexOf(MyTaskItemList.FirstOrDefault(y => y.MyTaskName == x.MyTaskName));
                MyTaskItemList.RemoveAt(index);
            });
        }