MainViewModel.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System.Windows.Controls;
  2. using Microsoft.Toolkit.Mvvm.Input;
  3. using MvvmHelpers;
  4. using MvvmHelpers.Commands;
  5. using MyMoviesWPF.MVVM.View.Pages;
  6. using MyMoviesWPF.MVVM.ViewModel.Core;
  7. namespace MyMoviesWPF.MVVM.ViewModel
  8. {
  9. public class MainViewModel : BaseViewModel
  10. {
  11. private string str;
  12. private RelayCommand _openCart;
  13. public Page _currentPage;
  14. public Page CurrentPage
  15. {
  16. get { return _currentPage; }
  17. set
  18. {
  19. if (_currentPage == value)
  20. return;
  21. _currentPage = value;
  22. OnPropertyChanged("CurrentPage");
  23. }
  24. }
  25. public string Cart
  26. {
  27. get
  28. {
  29. if (Service.CartMoviesCollection.Count > 0)
  30. {
  31. str = "Корзина(" + (Service.CartMoviesCollection.Count) + ')';
  32. }
  33. else
  34. {
  35. str = "Корзина";
  36. }
  37. return str;
  38. }
  39. set
  40. {
  41. if (str == value)
  42. return;
  43. str = value;
  44. OnPropertyChanged("Cart");
  45. }
  46. }
  47. public MainViewModel()
  48. {
  49. Service.MainViewModel = this;
  50. _currentPage = new CatalogPage();
  51. }
  52. public void UpdatePage(Page _page)
  53. {
  54. _currentPage = _page;
  55. OnPropertyChanged("CurrentPage");
  56. }
  57. public RelayCommand OpenCart
  58. {
  59. get
  60. {
  61. return _openCart
  62. ?? (_openCart = new RelayCommand(
  63. async () =>
  64. {
  65. CartPage page = new CartPage();
  66. UpdatePage(page);
  67. }));
  68. }
  69. }
  70. //UserViewModel _userViewModel = new UserViewModel();
  71. //private BaseViewModel _toolbar = new UserViewModel();
  72. //private BaseViewModel _view = new CatalogViewModel();
  73. //public BaseViewModel CurrentToolbar
  74. //{
  75. // get { return _toolbar; }
  76. // set
  77. // {
  78. // _toolbar = value;
  79. // OnPropertyChanged();
  80. // }
  81. //}
  82. //public BaseViewModel CurrentView
  83. //{
  84. // get { return _view; }
  85. // set
  86. // {
  87. // _view = value;
  88. // OnPropertyChanged();
  89. // }
  90. //}
  91. }
  92. }