using System.Collections.Generic; using DownKyi.Events; using DownKyi.Utils; using DownKyi.ViewModels.PageViewModels; using DownKyi.ViewModels.Toolbox; using Prism.Commands; using Prism.Events; using Prism.Regions; namespace DownKyi.ViewModels { public class ViewToolboxViewModel : ViewModelBase { public const string Tag = "PageToolbox"; private readonly IRegionManager regionManager; #region 页面属性申明 private List _tabHeaders; public List TabHeaders { get => _tabHeaders; set => SetProperty(ref _tabHeaders, value); } private int _selectTabId; public int SelectTabId { get => _selectTabId; set => SetProperty(ref _selectTabId, value); } #endregion public ViewToolboxViewModel(IRegionManager regionManager, IEventAggregator eventAggregator) : base( eventAggregator) { this.regionManager = regionManager; #region 属性初始化 TabHeaders = new List { new() { Id = 0, Title = DictionaryResource.GetString("BiliHelper") }, new() { Id = 1, Title = DictionaryResource.GetString("Delogo") }, new() { Id = 2, Title = DictionaryResource.GetString("ExtractMedia") } }; #endregion } #region 命令申明 // 返回事件 private DelegateCommand? _backSpaceCommand; public DelegateCommand BackSpaceCommand => _backSpaceCommand ??= new DelegateCommand(ExecuteBackSpace); /// /// 返回事件 /// private void ExecuteBackSpace() { var parameter = new NavigationParam { ViewName = ParentView, ParentViewName = null, Parameter = null }; EventAggregator.GetEvent().Publish(parameter); } // 左侧tab点击事件 private DelegateCommand? _leftTabHeadersCommand; public DelegateCommand LeftTabHeadersCommand => _leftTabHeadersCommand ??= new DelegateCommand(ExecuteLeftTabHeadersCommand); /// /// 左侧tab点击事件 /// /// private void ExecuteLeftTabHeadersCommand(object parameter) { if (parameter is not TabHeader tabHeader) { return; } var param = new NavigationParameters(); switch (tabHeader.Id) { case 0: regionManager.RequestNavigate("ToolboxContentRegion", ViewBiliHelperViewModel.Tag, param); break; case 1: regionManager.RequestNavigate("ToolboxContentRegion", ViewDelogoViewModel.Tag, param); break; case 2: regionManager.RequestNavigate("ToolboxContentRegion", ViewExtractMediaViewModel.Tag, param); break; } } #endregion /// /// 导航到页面时执行 /// /// public override void OnNavigatedTo(NavigationContext navigationContext) { base.OnNavigatedTo(navigationContext); // 进入设置页面时显示的设置项 SelectTabId = 0; PropertyChangeAsync(() => { regionManager.RequestNavigate("ToolboxContentRegion", ViewBiliHelperViewModel.Tag, new NavigationParameters()); }); } } }