public MainPageViewModel(INavigationService navigationService) { _navigationService = navigationService; 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; }); MyTaskItemSelectedCommand = new DelegateCommand(async() => { var fooPara = new NavigationParameters(); fooPara.Add("Record", MyTaskItemSelected.Clone()); await _navigationService.NavigateAsync("TaskDetailPage", fooPara); }); }
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); }); 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; }); }
public MainPageViewModel(INavigationService navigationService) { _navigationService = navigationService; 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; }); MyTaskItemSelectedCommand = new DelegateCommand(async() => { var fooPara = new NavigationParameters(); fooPara.Add("Record", MyTaskItemSelected.Clone()); fooPara.Add("Action", "S"); await _navigationService.NavigateAsync("TaskDetailPage", fooPara); }); AddCommand = new DelegateCommand(async() => { var fooPara = new NavigationParameters(); fooPara.Add("Record", new MyTaskItem() { MyTaskName = "請輸入工作名稱" }); fooPara.Add("Action", "A"); await _navigationService.NavigateAsync("TaskDetailPage", fooPara); }); DeleteCommand = new DelegateCommand <MyTaskItem>(x => { var fooEditTask = MyTaskItemList.FirstOrDefault(s => s.MyTaskName == x.MyTaskName); if (fooEditTask != null) { MyTaskItemList.Remove(fooEditTask); } }); }
public MainPageViewModel(INavigationService navigationService) { _navigationService = navigationService; 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; }); }
public MainPageViewModel(IPageDialogService dialogService, INavigationService navigationService, IEventAggregator eventAggregator) { _eventAggregator = eventAggregator; _navigationService = navigationService; _dialogService = dialogService; MyTaskItemSelectedCommand = new DelegateCommand(async() => { //await _dialogService.DisplayAlertAsync("Info", $"你選取的是 {MyTaskItemSelected.MyTaskName}", "OK"); NavigationParameters fooPara = new NavigationParameters(); // 為什麼這裡需要做 MemberwiseClone,不做,會有甚麼影響 fooPara.Add("MyTaskItem", MyTaskItemSelected.Clone() as MyTaskItem); 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; }); _eventAggregator.GetEvent <MyTaskItemEvent>().Subscribe(x => { var fooEditTask = MyTaskItemList.FirstOrDefault(s => s.MyTaskName == x.MyTaskItemSelected.MyTaskName); if (x.TaskMode == "Edit") { if (fooEditTask != null) { fooEditTask.MyTaskDate = x.MyTaskItemSelected.MyTaskDate; fooEditTask.MyTaskStatus = x.MyTaskItemSelected.MyTaskStatus; } } else if (x.TaskMode == "Delete") { if (fooEditTask != null) { MyTaskItemList.Remove(fooEditTask); } } else { MyTaskItemList.Insert(0, x.MyTaskItemSelected); } }); }