添加关闭窗口程序最小化到通知栏
This commit is contained in:
@@ -8,12 +8,15 @@
|
||||
xmlns:vm="clr-namespace:PMSWPF.ViewModels"
|
||||
xmlns:mo="clr-namespace:PMSWPF.Models"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:tb="http://hardcodet.net/taskbar"
|
||||
xmlns:taskbarNotification="http://www.hardcodet.net/taskbar"
|
||||
Title="设备管理系统"
|
||||
Width="1080"
|
||||
Height="800"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
WindowState="Maximized"
|
||||
Loaded="MainView_OnLoaded"
|
||||
Closing="Window_Closing"
|
||||
ui:WindowHelper.UseModernWindowStyle="True"
|
||||
ui:WindowHelper.SystemBackdropType="Mica"
|
||||
d:DataContext="{d:DesignInstance vm:MainViewModel}"
|
||||
@@ -37,6 +40,17 @@
|
||||
</DataTemplate>
|
||||
</Window.Resources>
|
||||
<Grid>
|
||||
<taskbarNotification:TaskbarIcon x:Name="MyNotifyIcon"
|
||||
ToolTipText="设备管理系统"
|
||||
IconSource="/AppIcon2.ico"
|
||||
DoubleClickCommand="{Binding ShowWindowCommand}">
|
||||
<taskbarNotification:TaskbarIcon.ContextMenu>
|
||||
<ContextMenu>
|
||||
<MenuItem Header="显示窗口" Command="{Binding ShowWindowCommand}" />
|
||||
<MenuItem Header="退出" Command="{Binding ExitApplicationCommand}" />
|
||||
</ContextMenu>
|
||||
</taskbarNotification:TaskbarIcon.ContextMenu>
|
||||
</taskbarNotification:TaskbarIcon>
|
||||
<ui:NavigationView ExpandedModeThresholdWidth="500"
|
||||
IsTabStop="False"
|
||||
PaneDisplayMode="Left"
|
||||
@@ -49,7 +63,7 @@
|
||||
MenuItemsSource="{Binding Menus}"
|
||||
MenuItemTemplate="{StaticResource NavigationViewMenuItem}"
|
||||
SelectionChanged="NavigationView_SelectionChanged">
|
||||
|
||||
|
||||
|
||||
<ui:NavigationView.AutoSuggestBox>
|
||||
<ui:AutoSuggestBox AutomationProperties.Name="Search">
|
||||
|
||||
@@ -12,6 +12,8 @@ namespace PMSWPF.Views;
|
||||
/// <summary>
|
||||
/// MainView.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
// using Hardcodet.NotifyIcon.Wpf;
|
||||
|
||||
public partial class MainView : Window
|
||||
{
|
||||
private readonly DataServices _dataServices;
|
||||
@@ -24,8 +26,26 @@ public partial class MainView : Window
|
||||
_dataServices = dataServices;
|
||||
DataContext = _viewModel;
|
||||
NlogHelper.Info("主界面加载成功");
|
||||
|
||||
// Set the NotifyIcon's DataContext to the ViewModel
|
||||
MyNotifyIcon.DataContext = _viewModel;
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
// Hide the window instead of closing it
|
||||
e.Cancel = true;
|
||||
Hide();
|
||||
}
|
||||
|
||||
public void ShowApplication()
|
||||
{
|
||||
Show();
|
||||
WindowState = WindowState.Normal;
|
||||
Activate();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 左边菜单项被点击的事件,切换右边的视图
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user