FlyoutService.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Linq;
  2. using Prism.Regions;
  3. using Prism.Commands;
  4. using System.Windows.Input;
  5. using MahApps.Metro.Controls;
  6. using SHJX.Service.Common.Constants;
  7. using SHJX.Service.Common.Interface;
  8. namespace SHJX.Service.Common.Service
  9. {
  10. public class FlyoutService : IFlyoutService
  11. {
  12. private readonly IRegionManager _regionManager;
  13. private readonly IApplicationCommands _applicationCommands;
  14. public ICommand ShowFlyoutCommand { get; private set; }
  15. public FlyoutService(IRegionManager regionManager, IApplicationCommands applicationCommands)
  16. {
  17. _regionManager = regionManager;
  18. _applicationCommands = applicationCommands;
  19. ShowFlyoutCommand = new DelegateCommand<string>(ShowFlyout);
  20. //注册子命令给全局复合命令
  21. _applicationCommands.ShowCommand.RegisterCommand(this.ShowFlyoutCommand);
  22. }
  23. public void ShowFlyout(string flyoutName)
  24. {
  25. IRegion region = _regionManager.Regions[RegionNames.FlyoutRegion];
  26. if (region is null)
  27. {
  28. return;
  29. }
  30. if (region.Views.FirstOrDefault(v => v is IFlyoutView view && view.FlyoutName.Equals(flyoutName)) is Flyout flyout)
  31. {
  32. flyout.IsOpen = !flyout.IsOpen;
  33. }
  34. }
  35. }
  36. }