MainViewModel.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. return str;
  30. }
  31. set
  32. {
  33. if (str == value)
  34. return;
  35. str = value;
  36. OnPropertyChanged("Cart");
  37. }
  38. }
  39. public MainViewModel()
  40. {
  41. UpdateCartStr();
  42. Service.MainViewModel = this;
  43. _currentPage = new CatalogPage();
  44. }
  45. public void UpdatePage(Page _page)
  46. {
  47. _currentPage = _page;
  48. OnPropertyChanged("CurrentPage");
  49. }
  50. public void UpdateCartStr()
  51. {
  52. if (Service.CartMoviesCollection.Count > 0)
  53. {
  54. str = "Корзина(" + (Service.CartMoviesCollection.Count) + ')';
  55. }
  56. else
  57. {
  58. str = "Корзина";
  59. }
  60. OnPropertyChanged("Cart");
  61. }
  62. public RelayCommand OpenCart
  63. {
  64. get
  65. {
  66. return _openCart
  67. ?? (_openCart = new RelayCommand(
  68. async () =>
  69. {
  70. CartPage page = new CartPage();
  71. UpdatePage(page);
  72. }));
  73. }
  74. }
  75. //UserViewModel _userViewModel = new UserViewModel();
  76. //private BaseViewModel _toolbar = new UserViewModel();
  77. //private BaseViewModel _view = new CatalogViewModel();
  78. //public BaseViewModel CurrentToolbar
  79. //{
  80. // get { return _toolbar; }
  81. // set
  82. // {
  83. // _toolbar = value;
  84. // OnPropertyChanged();
  85. // }
  86. //}
  87. //public BaseViewModel CurrentView
  88. //{
  89. // get { return _view; }
  90. // set
  91. // {
  92. // _view = value;
  93. // OnPropertyChanged();
  94. // }
  95. //}
  96. }
  97. }