| 12345678910111213141516171819202122232425262728293031323334353637383940 |
- using System.Linq;
- using Prism.Regions;
- using Prism.Commands;
- using System.Windows.Input;
- using MahApps.Metro.Controls;
- using SHJX.Service.Common.Constants;
- using SHJX.Service.Common.Interface;
- namespace SHJX.Service.Common.Service
- {
- public class FlyoutService : IFlyoutService
- {
- private readonly IRegionManager _regionManager;
- private readonly IApplicationCommands _applicationCommands;
- public ICommand ShowFlyoutCommand { get; private set; }
- public FlyoutService(IRegionManager regionManager, IApplicationCommands applicationCommands)
- {
- _regionManager = regionManager;
- _applicationCommands = applicationCommands;
- ShowFlyoutCommand = new DelegateCommand<string>(ShowFlyout);
- //注册子命令给全局复合命令
- _applicationCommands.ShowCommand.RegisterCommand(this.ShowFlyoutCommand);
- }
- public void ShowFlyout(string flyoutName)
- {
- IRegion region = _regionManager.Regions[RegionNames.FlyoutRegion];
- if (region is null)
- {
- return;
- }
- if (region.Views.FirstOrDefault(v => v is IFlyoutView view && view.FlyoutName.Equals(flyoutName)) is Flyout flyout)
- {
- flyout.IsOpen = !flyout.IsOpen;
- }
- }
- }
- }
|