Files
DMS/Views/MainView.xaml.cs

79 lines
2.1 KiB
C#
Raw Normal View History

2025-05-29 08:58:58 +08:00
using System.Windows;
2025-06-10 20:55:39 +08:00
using iNKORE.UI.WPF.Modern.Controls;
using Microsoft.Extensions.DependencyInjection;
using PMSWPF.Enums;
2025-06-30 13:06:51 +08:00
using PMSWPF.Helper;
using PMSWPF.Models;
using PMSWPF.Services;
2025-05-29 08:58:58 +08:00
using PMSWPF.ViewModels;
namespace PMSWPF.Views;
/// <summary>
/// MainView.xaml 的交互逻辑
/// </summary>
// using Hardcodet.NotifyIcon.Wpf;
public partial class MainView : Window
2025-05-29 08:58:58 +08:00
{
private readonly DataServices _dataServices;
private MainViewModel _viewModel;
2025-07-06 19:51:53 +08:00
public MainView(DataServices dataServices)
{
InitializeComponent();
_viewModel = App.Current.Services.GetRequiredService<MainViewModel>();
_dataServices = dataServices;
DataContext = _viewModel;
2025-07-06 19:51:53 +08:00
NlogHelper.Info("主界面加载成功");
// Set the NotifyIcon's DataContext to the ViewModel
MyNotifyIcon.DataContext = _viewModel;
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
var settings = Config.ConnectionSettings.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();
}
2025-05-29 08:58:58 +08:00
/// <summary>
/// 左边菜单项被点击的事件,切换右边的视图
2025-05-29 08:58:58 +08:00
/// </summary>
/// <param name="sender"></param>
/// <param name="args"></param>
private async void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
2025-05-29 08:58:58 +08:00
{
var menu = args.SelectedItem as MenuBean;
if (menu != null)
2025-05-29 08:58:58 +08:00
{
await _viewModel.MenuSelectionChanged(menu);
}
else
{
NotificationHelper.ShowError("选择的菜单项为空!");
2025-06-10 20:55:39 +08:00
}
2025-05-29 08:58:58 +08:00
}
private async void MainView_OnLoaded(object sender, RoutedEventArgs e)
{
_viewModel.OnLoaded();
}
}