Beispiel #1
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            _dishViewModel = new DishViewModel();
            _dishWindow = new DishWindow
            {
                DataContext = _dishViewModel
            };

            _ingredientsViewModel = new IngredientsViewModel();
            _ingredientsWindow = new IngredientsWindow
            {
                DataContext = _ingredientsViewModel
            };

            _preparationViewModel = new PreparationViewModel();
            _preparationWindow = new PreparationWindow
            {
                DataContext = _preparationViewModel
            };

            _mainViewModel = new MainViewModel(_dishWindow, _ingredientsWindow, _preparationWindow);
            _mainWindow = new MainWindow
            {
                DataContext = _mainViewModel
            };

            _mainWindow.Show();
        }
Beispiel #2
0
        public MainViewModel(DishWindow dishWindow, IngredientsWindow ingredientsWindow, PreparationWindow preparationWindow)
        {
            _dinner = new Dinner();

            _dishWindow = dishWindow;
            _ingredientsWindow = ingredientsWindow;
            _preparationWindow = preparationWindow;

            _dishViewModel = (DishViewModel) _dishWindow.DataContext;
            _ingredientsViewModel = (IngredientsViewModel) _ingredientsWindow.DataContext;
            _preparationViewModel = (PreparationViewModel) _preparationWindow.DataContext;

            Starters = new ObservableCollection<Dish>();
            Mains = new ObservableCollection<Dish>();
            Desserts = new ObservableCollection<Dish>();
            Menu = new ObservableCollection<Dish>();

            _hideErrorTextTimer = new System.Timers.Timer(ErrorTextDisplayTime) {AutoReset = false};
            _hideErrorTextTimer.Elapsed += (sender, args) => Application.Current.Dispatcher.Invoke(() => ErrorTextVisible = false);

            ShowPreparations = new DelegateCommand(o =>
            {
                _preparationViewModel.Starter = _dinner.GetSelectedDish(DishType.Starter);
                _preparationViewModel.Main = _dinner.GetSelectedDish(DishType.Main);
                _preparationViewModel.Dessert = _dinner.GetSelectedDish(DishType.Dessert);
                _preparationWindow.Show();
            }, o => Menu.Any());
            ShowIngredients = new DelegateCommand(o =>
            {
                _ingredientsViewModel.Ingredients = _dinner.AllIngredients;
                _ingredientsWindow.Show();
            }, o => Menu.Any());

            _dinner.MenuChanged += OnMenuChanged;
            _dinner.FilteredDishes += DinnerOnFilteredDishes;
            _dinner.ErrorGettingFilteredDishes += DinnerOnErrorGettingFilteredDishes;
            _dinner.DishesChanged += OnDishesChanged;
            _dinner.NumberOfGuestsChanged += OnNumberOfGuestsChanged;
        }