private NumberDiceViewModel getNumberDiceViewModel() { var numDiceVm = new NumberDiceViewModel() { View = ViewReference.NumberDicePage }; _vmRegistry.RegisterViewModel(typeof(NumberDicePage), x => { numDiceVm.Page = x as ISubmit; return numDiceVm; }); return numDiceVm; }
public MainViewModel(NumberDiceViewModel numDiceViewModel, NumberSidesViewModel numSidesViewModel, RollModeViewModel rollModeViewModel, RandomModeViewModel randomModeViewModel) { if (numDiceViewModel == null) throw new ArgumentNullException("numDiceViewModel is null."); if (numSidesViewModel == null) throw new ArgumentNullException("numSidesViewModel is null."); if (rollModeViewModel == null) throw new ArgumentNullException("rollModeViewModel is null."); if (randomModeViewModel == null) throw new ArgumentNullException("randomModeViewModel is null."); SetupPages = new ObservableCollection<IPageViewModel>(); Dice = new ObservableCollection<IDieViewModel>(); Statistics = new ObservableCollection<IStatisticViewModel>(); _rollCommand = new DelegateCommand(x => randomModeViewModel.GeneratorIsReady, x => rollDice()); _numDiceViewModel = numDiceViewModel; _numDiceViewModel.NumberDiceChanged += (sender, e) => onSetupChanged(); SetupPages.Add(_numDiceViewModel); _numSidesViewModel = numSidesViewModel; _numSidesViewModel.NumberSidesChanged += (sender, e) => onSetupChanged(); SetupPages.Add(_numSidesViewModel); _rollModeViewModel = rollModeViewModel; _rollModeViewModel.ModeChanged += (sender, e) => onSetupChanged(); SetupPages.Add(_rollModeViewModel); _randomModeViewModel = randomModeViewModel; _randomModeViewModel.RandomModeChanged += (sender, e) => onSetupChanged(); _randomModeViewModel.Ready += (sender, e) => _rollCommand.RaiseCanExecuteChanged(); _randomModeViewModel.Error += (sender, e) => _rollCommand.RaiseCanExecuteChanged(); // TODO: Add error checking before adding this feature //SetupPages.Add(_randomModeViewModel); onSetupChanged(); }