- 新增NavigationType枚举定义导航类型 - 新增NavigationParameter类用于传递导航参数 - 重构INavigationService和INavigatable接口 - 更新NavigationService实现以支持新的导航方式 - 更新DeviceDetailViewModel, DevicesViewModel, VariableHistoryViewModel, VariableTableViewModel, MqttsViewModel等 - 使ViewModelBase实现INavigatable接口 - 更新MainView中的菜单选择导航逻辑 - 优化VariableHistoryView界面布局,添加返回变量表按钮
85 lines
2.5 KiB
C#
85 lines
2.5 KiB
C#
using System.Collections.ObjectModel;
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using DMS.Core.Enums;
|
|
using DMS.Core.Models;
|
|
using DMS.WPF.Helper;
|
|
using DMS.WPF.Interfaces;
|
|
using DMS.WPF.Services;
|
|
using DMS.WPF.ViewModels.Items;
|
|
using DMS.WPF.Views;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
// AddAsync this using directive
|
|
// AddAsync this using directive
|
|
|
|
namespace DMS.WPF.ViewModels;
|
|
|
|
/// <summary>
|
|
/// 主视图模型,负责应用程序的主导航和数据管理。
|
|
/// </summary>
|
|
public partial class MainViewModel : ViewModelBase
|
|
{
|
|
private readonly IDialogService _dialogService;
|
|
private readonly IWPFDataService _wpfDataService;
|
|
private readonly IDataStorageService _dataStorageService;
|
|
private readonly INavigationService _navigationService;
|
|
private readonly ILogger<MainViewModel> _logger;
|
|
|
|
/// <summary>
|
|
/// 当前显示的视图模型。
|
|
/// </summary>
|
|
[ObservableProperty]
|
|
private ViewModelBase _currentViewModel;
|
|
|
|
/// <summary>
|
|
/// 应用程序的菜单列表。
|
|
/// </summary>
|
|
[ObservableProperty]
|
|
private ObservableCollection<MenuItemViewModel> _menuTrees;
|
|
|
|
/// <summary>
|
|
/// 初始化 <see cref="MainViewModel"/> 类的新实例。
|
|
/// </summary>
|
|
/// <param name="navgatorServices">导航服务。</param>
|
|
/// <param name="dataServices">数据服务。</param>
|
|
/// <param name="dialogService">对话框服务。</param>
|
|
/// <param name="logger">日志记录器。</param>
|
|
/// <param name="wpfDataService"></param>
|
|
public MainViewModel(IWPFDataService wpfDataService ,IDataStorageService dataStorageService,INavigationService navigationService,
|
|
ILogger<MainViewModel> logger)
|
|
{
|
|
_wpfDataService = wpfDataService;
|
|
_dataStorageService = dataStorageService;
|
|
_navigationService = navigationService;
|
|
_logger = logger;
|
|
MenuTrees = _dataStorageService.MenuTrees;
|
|
|
|
CurrentViewModel = new HomeViewModel();
|
|
CurrentViewModel.OnLoaded();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示主窗口的命令。
|
|
/// </summary>
|
|
[RelayCommand]
|
|
private void ShowWindow()
|
|
{
|
|
if (App.Current.MainWindow is MainView mainWindow)
|
|
{
|
|
mainWindow.ShowApplication();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 退出应用程序的命令。
|
|
/// </summary>
|
|
[RelayCommand]
|
|
private void ExitApplication()
|
|
{
|
|
// Application.Current.Shutdown();
|
|
}
|
|
|
|
|
|
|
|
} |