2025-07-19 09:25:01 +08:00
|
|
|
using System.Windows;
|
|
|
|
|
using DMS.WPF.Services;
|
|
|
|
|
using DMS.WPF.ViewModels;
|
2025-06-10 20:55:39 +08:00
|
|
|
using iNKORE.UI.WPF.Modern.Controls;
|
2025-07-02 12:01:20 +08:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2025-07-18 22:21:16 +08:00
|
|
|
using DMS.Core.Enums;
|
2025-10-03 22:28:58 +08:00
|
|
|
using DMS.Core.Models;
|
|
|
|
|
using DMS.WPF.Interfaces;
|
2025-07-26 18:58:52 +08:00
|
|
|
using DMS.WPF.ViewModels.Items;
|
2025-05-29 08:58:58 +08:00
|
|
|
|
2025-07-19 09:25:01 +08:00
|
|
|
namespace DMS.WPF.Views;
|
2025-06-23 17:01:06 +08:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// MainView.xaml 的交互逻辑
|
|
|
|
|
/// </summary>
|
2025-07-07 14:01:37 +08:00
|
|
|
// using Hardcodet.NotifyIcon.Wpf;
|
|
|
|
|
|
2025-06-23 17:01:06 +08:00
|
|
|
public partial class MainView : Window
|
2025-05-29 08:58:58 +08:00
|
|
|
{
|
2025-06-25 22:33:57 +08:00
|
|
|
private MainViewModel _viewModel;
|
2025-06-30 14:19:22 +08:00
|
|
|
|
2025-07-26 12:19:05 +08:00
|
|
|
public MainView()
|
2025-06-23 17:01:06 +08:00
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2025-07-02 12:01:20 +08:00
|
|
|
_viewModel = App.Current.Services.GetRequiredService<MainViewModel>();
|
|
|
|
|
DataContext = _viewModel;
|
2025-09-04 17:29:24 +08:00
|
|
|
|
2025-07-07 14:01:37 +08:00
|
|
|
// Set the NotifyIcon's DataContext to the ViewModel
|
|
|
|
|
MyNotifyIcon.DataContext = _viewModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
|
|
|
{
|
2025-06-23 17:01:06 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-07 14:01:37 +08:00
|
|
|
public void ShowApplication()
|
|
|
|
|
{
|
|
|
|
|
Show();
|
|
|
|
|
WindowState = WindowState.Normal;
|
|
|
|
|
Activate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-05-29 08:58:58 +08:00
|
|
|
/// <summary>
|
2025-06-23 17:01:06 +08:00
|
|
|
/// 左边菜单项被点击的事件,切换右边的视图
|
2025-05-29 08:58:58 +08:00
|
|
|
/// </summary>
|
2025-06-23 17:01:06 +08:00
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="args"></param>
|
2025-07-02 12:01:20 +08:00
|
|
|
private async void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
|
2025-05-29 08:58:58 +08:00
|
|
|
{
|
2025-07-30 12:09:00 +08:00
|
|
|
var menu = args.SelectedItem as MenuItemViewModel;
|
2025-07-26 18:58:52 +08:00
|
|
|
if (menu != null)
|
|
|
|
|
{
|
2025-10-03 22:28:58 +08:00
|
|
|
|
|
|
|
|
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));
|
2025-07-26 18:58:52 +08:00
|
|
|
}
|
|
|
|
|
|
2025-05-29 08:58:58 +08:00
|
|
|
}
|
2025-06-25 22:33:57 +08:00
|
|
|
|
|
|
|
|
private async void MainView_OnLoaded(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
_viewModel.OnLoaded();
|
|
|
|
|
}
|
2025-06-23 17:01:06 +08:00
|
|
|
}
|