Пример #1
0
        /// <summary>
        /// Creates and adds a few ItemViewModel objects into the Items collection.
        /// </summary>
        public void LoadData()
        {
            // deserialize data.
            ObservableCollection <Task> tasks = _persistenceService.GetTasks();

            foreach (Task task in tasks)
            {
                task.PropertyChanged += TaskChanged;
            }
            tasks.CollectionChanged += (o, e) =>
            {
                if (e.NewItems != null)
                {
                    foreach (Task newItem in e.NewItems)
                    {
                        newItem.PropertyChanged += TaskChanged;
                    }
                }

                if (e.OldItems != null)
                {
                    foreach (Task oldItem in e.OldItems)
                    {
                        oldItem.PropertyChanged -= TaskChanged;
                    }
                }
            };

            InitFilters(tasks);

            this.IsDataLoaded = true;
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            ApplicationName = "OPEN TODO";
            Filters = new ObservableCollection<FiltersViewModel>();

            EditTaskCommand = new DelegateCommand<Task>(OnEditCommandExecuted);
            AddCommand = new DelegateCommand(OnAddCommandExecuted);

            _persistenceService = new XmlPersistenceService();
            _taskLists = _persistenceService.GetTaskLists();
            _tasks = _persistenceService.GetTasks();

            // refresh the list of filters. i.e. fixed labels + taskLists
            _taskLists.CollectionChanged += (o, e) => InitFilters(_tasks);

            ViewModelLocatorService.SetViewModel(typeof(EditListsView), new EditListsViewModel(_taskLists));
            ViewModelLocatorService.SetViewModel(typeof(AddTaskView), new AddTaskViewModel(_tasks, _taskLists));
            ViewModelLocatorService.SetViewModel(typeof(EditTaskView), new EditTaskViewModel(_tasks, _taskLists));
            ViewModelLocatorService.SetViewModel(typeof(About), new AboutViewModel());

            ShowAboutCommand = new DelegateCommand(OnShowAboutCommand);
            ShowSettingsCommand  = new DelegateCommand(OnShowSettings);
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainViewModel"/> class.
        /// </summary>
        public MainViewModel()
        {
            ApplicationName = "OPEN TODO";
            Filters         = new ObservableCollection <FiltersViewModel>();

            EditTaskCommand = new DelegateCommand <Task>(OnEditCommandExecuted);
            AddCommand      = new DelegateCommand(OnAddCommandExecuted);

            _persistenceService = new XmlPersistenceService();
            _taskLists          = _persistenceService.GetTaskLists();
            _tasks = _persistenceService.GetTasks();

            // refresh the list of filters. i.e. fixed labels + taskLists
            _taskLists.CollectionChanged += (o, e) => InitFilters(_tasks);

            ViewModelLocatorService.SetViewModel(typeof(EditListsView), new EditListsViewModel(_taskLists));
            ViewModelLocatorService.SetViewModel(typeof(AddTaskView), new AddTaskViewModel(_tasks, _taskLists));
            ViewModelLocatorService.SetViewModel(typeof(EditTaskView), new EditTaskViewModel(_tasks, _taskLists));
            ViewModelLocatorService.SetViewModel(typeof(About), new AboutViewModel());

            ShowAboutCommand    = new DelegateCommand(OnShowAboutCommand);
            ShowSettingsCommand = new DelegateCommand(OnShowSettings);
        }