ProductsViewModel.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using MahApps.Metro.Controls;
  2. using Prism.Commands;
  3. using Prism.Events;
  4. using Prism.Ioc;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using Prism.Services.Dialogs;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Collections.ObjectModel;
  11. using System.Linq;
  12. using TeamAAS_VP.Core;
  13. using TeamAAS_VP.Events;
  14. using TeamAAS_VP.Interfaces;
  15. using TeamAAS_VP.Models;
  16. using TeamAAS_VP.Models.Product;
  17. using TeamAAS_VP.Services;
  18. namespace TeamAAS_VP.ViewModels
  19. {
  20. public class ProductsViewModel : BindableBase, IConfirmNavigationRequest
  21. {
  22. IRegionManager _regionManager;
  23. IEventAggregator _eventAggregator;
  24. IContainerProvider _container;
  25. IDialogService _dialogService;
  26. IProductService _productService;
  27. #region 属性
  28. #endregion
  29. #region 命令
  30. private DelegateCommand _LoadedCommand;
  31. public DelegateCommand LoadedCommand =>
  32. _LoadedCommand ?? (_LoadedCommand = new DelegateCommand(ExecuteLoadedCommand));
  33. #endregion
  34. #region 事件
  35. #endregion
  36. public ProductsViewModel(IRegionManager regionManager, IEventAggregator ea, IContainerProvider container, IDialogService dialogService,
  37. IProductService productService)
  38. {
  39. _regionManager = regionManager;
  40. _eventAggregator = ea;
  41. _container = container;
  42. _dialogService = dialogService;
  43. _productService = productService;
  44. //订阅权限登录事件
  45. _eventAggregator.GetEvent<UserLoginNotification>().Subscribe(LoginChange);
  46. }
  47. #region 方法
  48. bool isFirstShow = false;
  49. void ExecuteLoadedCommand()
  50. {
  51. if (!isFirstShow)
  52. {
  53. _regionManager.RequestNavigate("ProductRegionContext", "ProductHome");
  54. isFirstShow = true;
  55. }
  56. }
  57. #endregion
  58. #region 继承
  59. /// <summary>
  60. /// 确认导航请求时调用。此方法允许您在导航之前执行一些操作。
  61. /// </summary>
  62. /// <param name="navigationContext"></param>
  63. /// <param name="continuationCallback"></param>
  64. public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback)
  65. {
  66. continuationCallback(true);
  67. }
  68. /// <summary>
  69. /// 接收导航请求时调用。传入导航参数,包含有关导航目标的信息。
  70. /// </summary>
  71. /// <param name="navigationContext"></param>
  72. /// <exception cref="NotImplementedException"></exception>
  73. public async void OnNavigatedTo(NavigationContext navigationContext)
  74. {
  75. }
  76. /// <summary>
  77. /// 是否允许导航到此视图模型。
  78. /// </summary>
  79. /// <param name="navigationContext"></param>
  80. /// <returns></returns>
  81. public bool IsNavigationTarget(NavigationContext navigationContext)
  82. {
  83. return true;
  84. }
  85. /// <summary>
  86. /// 导航离开此视图模型时调用。您可以在此处执行清理操作或保存状态。
  87. /// </summary>
  88. /// <param name="navigationContext"></param>
  89. public void OnNavigatedFrom(NavigationContext navigationContext)
  90. {
  91. }
  92. #endregion
  93. private void LoginChange(Models.User user)
  94. {
  95. }
  96. }
  97. }