/// <summary>
        /// Constructor of the class
        /// </summary>
        /// <param name="taskModel"></param>
        /// <param name="targetList"></param>
        /// <param name="dataConnector"></param>
        /// <param name="mainPage"></param>
        /// <param name="state"></param>
        public DefaultTaskViewModel(ITaskModel taskModel, ObservableCollection<ITaskViewModel> targetList, IDataConnector dataConnector, MainPage mainPage, TaskState state)
        {
            TaskModel = taskModel;
            _targetList = targetList;
            _dataConnector = dataConnector;
            ItemVisualWidth = mainPage.ActualWidth;

            // Commands
            Break = new ViewModelCommand()
            {
                Command = new RelayCommand(r => BreakTask()),
                Text = "Break"
            };

            PunchOut = new ViewModelCommand
            {
                Command = new RelayCommand(r => FinishTask()),
                Text = "Finished",
                ImagePath = @"Images/finish.png"
            };

            DeleteFromList = new ViewModelCommand
            {
                Command = new RelayCommand(
                    r =>
                    {
                        if (targetList != null && targetList.Contains(this))
                        {
                            targetList.Remove(this);
                            _dataConnector.DeleteTask(taskModel.Id);
                        }
                    }),
                Text = "Delete",
                ImagePath = "Images/delete.png"
            };

            // Timer Init
            _timer = new DispatcherTimer();
            _timer.Tick += timer_Tick;
            _timer.Interval = TimeSpan.FromSeconds(1);
            _timer.Start();

            // Setstate
            State = state;
            _initLoad = false;
        }
Пример #2
0
        /// <summary>
        /// Constructor of the class.
        /// </summary>
        public MainViewModel(MainPage mainPage)
        {
            _mainPage = mainPage;

            // Init Commands
            PunchIn = new ViewModelCommand
            {
                Command = new RelayCommand(r => ShowInputDialog = true),
                Text = "Punch-in!",
                ImagePath = @"Images/play.png"
            };

            CloseInputDialog = new ViewModelCommand
            {
                Command = new RelayCommand(r => CreateTask()),
                Text = "Create task"
            };

            CloseDialog = new ViewModelCommand
            {
                Command = new RelayCommand(
                    r =>
                    {
                        ShowInputDialog = false;
                    }),
                Text = "X"
            };

            CreateOutputFile = new ViewModelCommand
            {
                Command = new RelayCommand(r => GenerateOutputFile()),
                Text = "Save to file",
                ImagePath = @"Images/save.png"
            };

            // Init Taskcollection.
            Tasks = new ObservableCollection<ITaskViewModel>();

            // Init DataConnector
            _dataConnector = new XmlDatabaseConnector(Tasks, _mainPage);
            _mainPage.MainPage_SizeChanged(null, null);
        }