131 lines
3.6 KiB
C#
131 lines
3.6 KiB
C#
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 Prism.Services.Dialogs;
|
|
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<NavigationItem>(Navigate);
|
|
}
|
|
|
|
public INavigationMenuService MenuService { get; }
|
|
public SysRunService SysService { get; }
|
|
public IEventAggregator EventAggregator { get; }
|
|
public DelegateCommand<NavigationItem> 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<string> _TopDrawerCmd;
|
|
/// <summary>
|
|
/// 顶部弹窗按钮命令
|
|
/// </summary>
|
|
public DelegateCommand<string> TopDrawerCmd
|
|
{
|
|
set
|
|
{
|
|
_TopDrawerCmd = value;
|
|
}
|
|
get
|
|
{
|
|
if (_TopDrawerCmd == null)
|
|
{
|
|
_TopDrawerCmd = new DelegateCommand<string>((p) => TopDrawerCmdCall(p));
|
|
}
|
|
return _TopDrawerCmd;
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 弹窗数据
|
|
/// </summary>
|
|
/// <param name="p"></param>
|
|
private void TopDrawerCmdCall(string Name)
|
|
{
|
|
//测试数据
|
|
IsTopDrawerOpen = false;
|
|
|
|
EventAggregator.GetEvent<ComDialogEvent>().Publish(new ComDialogMsg() { Name = Name, Par = null });
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 导航到页面信息
|
|
/// </summary>
|
|
/// <param name="pageName"></param>
|
|
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);
|
|
}
|
|
}
|
|
}
|