Advertisement
Guest User

MainWindowViewModel

a guest
Sep 12th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using Margo.UI.Utilities;
  2.  
  3. namespace Margo.UI.ViewModel
  4. {
  5.     internal class MainWindowViewModel : BaseViewModel
  6.     {
  7.  
  8.         private BaseViewModel _currentViewModel;
  9.  
  10.         private readonly AddProductViewModel _addProductViewModel = new AddProductViewModel();
  11.         private readonly ProductsViewModel _productsViewModel = new ProductsViewModel();
  12.         private readonly ShoppingListViewModel _shoppingListViewModel = new ShoppingListViewModel();
  13.  
  14.         public MainWindowViewModel()
  15.         {
  16.             CurrentViewModel = _shoppingListViewModel;
  17.             NavCommand = new RelayCommand<string>(OnNav);
  18.             _shoppingListViewModel.AddProductRequested += NavToAddProduct;
  19.         }
  20.  
  21.         private void NavToAddProduct()
  22.         {
  23.             CurrentViewModel = _addProductViewModel;
  24.         }
  25.  
  26.         public RelayCommand<string> NavCommand { get; private set; }
  27.  
  28.         public BaseViewModel CurrentViewModel
  29.         {
  30.             get { return _currentViewModel; }
  31.             set { SetProperty(ref _currentViewModel, value); }
  32.         }
  33.  
  34.         private void OnNav(string destination)
  35.         {
  36.             switch (destination)
  37.             {
  38.                 case "shoppingList":
  39.                     CurrentViewModel = _shoppingListViewModel;
  40.                     break;
  41.                 case "products":
  42.                     CurrentViewModel = _productsViewModel;
  43.                     break;
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement