コード例 #1
0
 public NewTaskVM()
 {
     Create = new DelegateCommand(() =>
     {
         CurrentTasks.Instance().InsertNewTask(task);
         TaskCreated?.Invoke();
     });
 }
コード例 #2
0
        public MainVM()
        {
            TaskList          = new ObservableCollection <Task>(CurrentTasks.Instance().Tasks);
            OpenNewTaskWindow = new DelegateCommand(openNewTaskWindow);
            StartTask         = new DelegateCommand(startTask);

            ((INotifyCollectionChanged)CurrentTasks.Instance().Tasks).CollectionChanged += (s, a) =>
            {
                if (a.NewItems?.Count == 1)
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                                                                          TaskList.Add(a.NewItems[0] as Task)));
                }
                if (a.OldItems?.Count == 1)
                {
                    Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                                                                          TaskList.Remove(a.OldItems[0] as Task)));
                }
            };
        }