Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            if (IsInDesignMode)
            {
                // Code runs in Blend --> create design time data.
                Counters = new ObservableCollection <CounterViewModel>(
                    new List <CounterViewModel>
                {
                    new CounterViewModel(Guid.NewGuid(), 6, "Foo"),
                    new CounterViewModel(Guid.NewGuid(), 9, null)
                    {
                        NameChanging = true
                    },
                    new CounterViewModel(Guid.NewGuid(), 0, "Bar"),
                });
            }
            else
            {
                counterApi = new CounterApi();

                AddCounter = new RelayCommand(OnAddCounter);
                Update     = new RelayCommand(() => UpdateView());
                Counters   = new ObservableCollection <CounterViewModel>();

                CounterStore.EventAdded += (s, e) => UpdateView();
                UpdateView();
            }

            Statistics = new StatisticsViewModel();
        }
        public CounterViewModel(Guid id, int count, string name)
        {
            if (!IsInDesignMode)
            {
                counterApi       = new CounterApi();
                Remove           = new RelayCommand(OnRemove);
                Increment        = new RelayCommand(OnIncrement);
                Decrement        = new RelayCommand(OnDecrement);
                ChangeName       = new RelayCommand(OnChangeName);
                SaveNameChange   = new RelayCommand(OnSaveNameChange);
                CancelNameChange = new RelayCommand(OnCancelNameChange);
            }

            Id    = id;
            Count = count;
            Name  = name;
        }