UserWindowViewModel.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using WpfApp29.Pages;
  7. namespace WpfApp29.ViewModels
  8. {
  9. internal class UserWindowViewModel
  10. {
  11. public UserWindowViewModel()
  12. {
  13. AppHelper.GetWindowAtType<UserWindow>()?.FramePages.Navigate(MainPage);
  14. }
  15. private MainPage? _mainPage;
  16. private AccountPage? _accountPage;
  17. private UserListPage? _userListPage;
  18. public MainPage MainPage
  19. {
  20. get => _mainPage ??= new MainPage();
  21. }
  22. public AccountPage AccountPage
  23. {
  24. get => _accountPage ??= new AccountPage();
  25. }
  26. public UserListPage UserListPage
  27. {
  28. get => _userListPage ??= new UserListPage();
  29. }
  30. public RelayCommand? _commandGoMainMenu;
  31. public RelayCommand CommandGoMainMenu
  32. {
  33. get
  34. {
  35. return _commandGoMainMenu ??= new RelayCommand(
  36. x =>
  37. {
  38. AppHelper.GetWindowAtType<UserWindow>()?.FramePages.Navigate(MainPage);
  39. },
  40. x =>
  41. {
  42. if (AppHelper.GetWindowAtType<UserWindow>()?.FramePages.Content is MainPage)
  43. {
  44. return false;
  45. }
  46. return true;
  47. }
  48. );
  49. }
  50. }
  51. public RelayCommand? _commandGoAccount;
  52. public RelayCommand CommandGoAccount
  53. {
  54. get
  55. {
  56. return _commandGoAccount ??= new RelayCommand(
  57. x =>
  58. {
  59. AppHelper.GetWindowAtType<UserWindow>()?.FramePages.Navigate(AccountPage);
  60. },
  61. x =>
  62. {
  63. if (AppHelper.GetWindowAtType<UserWindow>()?.FramePages.Content is AccountPage)
  64. {
  65. return false;
  66. }
  67. return true;
  68. }
  69. );
  70. }
  71. }
  72. public RelayCommand? _commandGoUserList;
  73. public RelayCommand CommandGoUserList
  74. {
  75. get
  76. {
  77. return _commandGoUserList ??= new RelayCommand(
  78. x =>
  79. {
  80. AppHelper.GetWindowAtType<UserWindow>()?.FramePages.Navigate(UserListPage);
  81. },
  82. x =>
  83. {
  84. if (AppHelper.GetWindowAtType<UserWindow>()?.FramePages.Content is UserListPage)
  85. {
  86. return false;
  87. }
  88. return true;
  89. }
  90. );
  91. }
  92. }
  93. public RelayCommand? _commandGoExit;
  94. public RelayCommand CommandGoExit
  95. {
  96. get
  97. {
  98. return _commandGoExit ??= new RelayCommand(
  99. x =>
  100. {
  101. new MainWindow().Show();
  102. AppHelper.GetWindowAtType<UserWindow>()?.Close();
  103. }
  104. );
  105. }
  106. }
  107. }
  108. }