93 lines
2.4 KiB
C#
93 lines
2.4 KiB
C#
using CapMachine.Core;
|
|
using CapMachine.Core.IService;
|
|
using CapMachine.Wpf.Models;
|
|
using Prism.Commands;
|
|
using Prism.Regions;
|
|
|
|
namespace CapMachine.Wpf.ViewModels
|
|
{
|
|
public class MainViewModel : NavigationViewModel
|
|
{
|
|
public MainViewModel(IRegionManager region, INavigationMenuService menuService)
|
|
{
|
|
this.region = region;
|
|
MenuService = menuService;
|
|
NavigateCommand = new DelegateCommand<NavigationItem>(Navigate);
|
|
}
|
|
|
|
public INavigationMenuService MenuService { 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;
|
|
}
|
|
|
|
|
|
/// <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);
|
|
}
|
|
}
|
|
}
|