public MainPageViewModel(INavigationService navigationService) { _navigationService = navigationService; TapCommand = new DelegateCommand(() => { NavigationParameters para = new NavigationParameters(); para.Add("current", MyTaskSelected); EditMode = true; para.Add("EditMode", EditMode); _navigationService.NavigateAsync("DetailPage", para); }); RefreshCommand = new DelegateCommand(() => { Refresh(); IsRefreshing = false; }); AddCommand = new DelegateCommand(() => { var fooNewTask = new MyItem() { Date = DateTime.Now.AddDays(-3), Status = "還沒有" }; NavigationParameters para = new NavigationParameters(); para.Add("current", fooNewTask); EditMode = false; para.Add("EditMode", EditMode); _navigationService.NavigateAsync("DetailPage", para); }); DeleteCommand = new DelegateCommand <MyItem>((x) => { MyTasks.Remove(x); }); }
public void OnReceive(TaskStatusCompletedMessage message) { var task = MyTasks.FirstOrDefault(x => x.id == message.Id); if (task != null) { MyTasks.Remove(task); } task = DueTodayTasks.FirstOrDefault(x => x.id == message.Id); if (task != null) { DueTodayTasks.Remove(task); } task = DueTomorrowTasks.FirstOrDefault(x => x.id == message.Id); if (task != null) { DueTomorrowTasks.Remove(task); } task = DueWeekendTasks.FirstOrDefault(x => x.id == message.Id); if (task != null) { DueWeekendTasks.Remove(task); } }
public void OnNavigatedTo(NavigationParameters parameters) { //para.Add("current", MyItemSelected); //para.Add("SaveData", SaveData); //para.Add("EditMode", EditMode); if (parameters.ContainsKey("EditMode")) { EditMode = (bool)parameters["EditMode"]; if (parameters.ContainsKey("current")) { var fooUpdateItem = parameters["current"] as MyItem; if (parameters.ContainsKey("SaveData")) { var fooSaveData = (bool)parameters["SaveData"]; // 開始進行資料的 CRUD 處理 if (EditMode == true) { if (fooSaveData == true) { var fooItem = MyTasks.FirstOrDefault(x => x.Id == fooUpdateItem.Id); if (fooItem != null) { fooItem.Name = fooUpdateItem.Name; fooItem.Status = fooUpdateItem.Status; fooItem.Date = fooUpdateItem.Date; } } else { var fooItem = MyTasks.FirstOrDefault(x => x.Id == fooUpdateItem.Id); if (fooItem != null) { MyTasks.Remove(fooItem); } } } else { // Add New Item MyTasks.Insert(0, fooUpdateItem); } } } } Refresh(); }