using CapMachine.Core; using CapMachine.Core.IService; using CapMachine.Wpf.Models; using CapMachine.Wpf.PrismEvent; using CapMachine.Wpf.Services; using Prism.Commands; using Prism.Events; using Prism.Regions; using System.Windows.Input; namespace CapMachine.Wpf.ViewModels { public class MainViewModel : NavigationViewModel { public MainViewModel(IRegionManager region, INavigationMenuService menuService, SysRunService sysService, IEventAggregator eventAggregator) { this.region = region; MenuService = menuService; SysService = sysService; EventAggregator = eventAggregator; NavigateCommand = new DelegateCommand(Navigate); } public INavigationMenuService MenuService { get; } public SysRunService SysService { get; } public IEventAggregator EventAggregator { get; } public DelegateCommand NavigateCommand { get; private set; } private int selectedIndex = -1; public int SelectedIndex { get { return selectedIndex; } set { selectedIndex = value; RaisePropertyChanged(); } } private bool isTopDrawerOpen; private readonly IRegionManager region; public bool IsTopDrawerOpen { get { return isTopDrawerOpen; } set { isTopDrawerOpen = value; if (SelectedIndex == 0 && !value) SelectedIndex = -1; RaisePropertyChanged(); } } private void Navigate(NavigationItem item) { if (item == null) return; if (item.Name.Equals("系统")) { IsTopDrawerOpen = true; return; } NavigatePage(item.PageName); IsTopDrawerOpen = false; } //private DelegateCommand _WindowClosingCmd; ///// ///// 顶部弹窗按钮命令 ///// //public DelegateCommand WindowClosingCmd //{ // set // { // _WindowClosingCmd = value; // } // get // { // if (_WindowClosingCmd == null) // { // _WindowClosingCmd = new DelegateCommand(() => WindowClosingCmdCall()); // } // return _WindowClosingCmd; // } //} //private void WindowClosingCmdCall() //{ // var dd = 1; //} private DelegateCommand _TopDrawerCmd; /// /// 顶部弹窗按钮命令 /// public DelegateCommand TopDrawerCmd { set { _TopDrawerCmd = value; } get { if (_TopDrawerCmd == null) { _TopDrawerCmd = new DelegateCommand((p) => TopDrawerCmdCall(p)); } return _TopDrawerCmd; } } /// /// 弹窗数据 /// /// private void TopDrawerCmdCall(string Name) { //测试数据 IsTopDrawerOpen = false; EventAggregator.GetEvent().Publish(new ComDialogMsg() { Name = Name, Par = null }); } /// /// 导航到页面信息 /// /// private void NavigatePage(string pageName) { region.Regions["MainViewContentRegion"].RequestNavigate(pageName, back => { if (!(bool)back.Result) { System.Diagnostics.Debug.WriteLine(back.Error.Message); } }); } public override void OnNavigatedTo(NavigationContext navigationContext) { MenuService.Initialize(); //region.Regions["MainViewContentRegion"].RequestNavigate("DashboardView", back => //{ // if (!(bool)back.Result) // { // } //}); base.OnNavigatedTo(navigationContext); } } }