WPF实现最小化到任务栏
private winform.NotifyIcon notifyIcon;
public MainWindow()
{
InitializeComponent();
NotifyButton();
}
private void NotifyButton()
{
winform.MenuItem showApp = new winform.MenuItem() { Text = "显示主页面" };
winform.MenuItem exitApp = new winform.MenuItem() { Text = "退出程序" };
showApp.Click += ShowWindow;
exitApp.Click += ExitApp;
winform.ContextMenu iconMenu = new winform.ContextMenu();
iconMenu.MenuItems.AddRange(new winform.MenuItem[] { showApp, exitApp });
notifyIcon = new winform.NotifyIcon();
notifyIcon.Text = "NetTool";
System.IO.Stream ManifestStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("NetTool.icon.ico");
notifyIcon.Icon = new System.Drawing.Icon(ManifestStream);
notifyIcon.Visible = true;
notifyIcon.MouseDoubleClick += ShowWindow;
notifyIcon.ContextMenu = iconMenu;
}
private void ShowWindow(object sender, EventArgs e)
{
Visibility = Visibility.Visible;
}
private void ExitApp(object sender, EventArgs e)
{
Application.Current.Shutdown();
}
演示程序