- 新增NavigationType枚举定义导航类型 - 新增NavigationParameter类用于传递导航参数 - 重构INavigationService和INavigatable接口 - 更新NavigationService实现以支持新的导航方式 - 更新DeviceDetailViewModel, DevicesViewModel, VariableHistoryViewModel, VariableTableViewModel, MqttsViewModel等 - 使ViewModelBase实现INavigatable接口 - 更新MainView中的菜单选择导航逻辑 - 优化VariableHistoryView界面布局,添加返回变量表按钮
91 lines
2.6 KiB
C#
91 lines
2.6 KiB
C#
using System.Windows;
|
|
using DMS.WPF.Services;
|
|
using DMS.WPF.ViewModels;
|
|
using iNKORE.UI.WPF.Modern.Controls;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using DMS.Core.Enums;
|
|
using DMS.Core.Models;
|
|
using DMS.WPF.Interfaces;
|
|
using DMS.WPF.ViewModels.Items;
|
|
|
|
namespace DMS.WPF.Views;
|
|
|
|
/// <summary>
|
|
/// MainView.xaml 的交互逻辑
|
|
/// </summary>
|
|
// using Hardcodet.NotifyIcon.Wpf;
|
|
|
|
public partial class MainView : Window
|
|
{
|
|
private MainViewModel _viewModel;
|
|
|
|
public MainView()
|
|
{
|
|
InitializeComponent();
|
|
_viewModel = App.Current.Services.GetRequiredService<MainViewModel>();
|
|
DataContext = _viewModel;
|
|
|
|
// Set the NotifyIcon's DataContext to the ViewModel
|
|
MyNotifyIcon.DataContext = _viewModel;
|
|
}
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
{
|
|
// var settings = Config.AppSettings.Load();
|
|
// if (settings.MinimizeToTrayOnClose)
|
|
// {
|
|
// // Hide the window instead of closing it
|
|
// e.Cancel = true;
|
|
// Hide();
|
|
// }
|
|
// else
|
|
// {
|
|
// Application.Current.Shutdown();
|
|
// }
|
|
}
|
|
|
|
public void ShowApplication()
|
|
{
|
|
Show();
|
|
WindowState = WindowState.Normal;
|
|
Activate();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 左边菜单项被点击的事件,切换右边的视图
|
|
/// </summary>
|
|
/// <param name="sender"></param>
|
|
/// <param name="args"></param>
|
|
private async void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
|
|
{
|
|
var menu = args.SelectedItem as MenuItemViewModel;
|
|
if (menu != null)
|
|
{
|
|
|
|
NavigationType navigationType = NavigationType.None;
|
|
switch (menu.MenuType)
|
|
{
|
|
case MenuType.DeviceMenu:
|
|
navigationType=NavigationType.Device;
|
|
break;
|
|
case MenuType.VariableTableMenu:
|
|
navigationType=NavigationType.VariableTable;
|
|
break;
|
|
case MenuType.MqttMenu:
|
|
navigationType=NavigationType.Mqtt;
|
|
break;
|
|
|
|
}
|
|
|
|
var navigationService= App.Current.Services.GetRequiredService<INavigationService>();
|
|
navigationService.NavigateToAsync(this,new NavigationParameter(menu.TargetViewKey,menu.TargetId,navigationType));
|
|
}
|
|
|
|
}
|
|
|
|
private async void MainView_OnLoaded(object sender, RoutedEventArgs e)
|
|
{
|
|
_viewModel.OnLoaded();
|
|
}
|
|
} |