ShutdownMode
을 OnExplicitShutdown
으로 설정하고 Application.OnStartup
의 트레이 아이콘을 표시하십시오. 이 예에서는 WinForms
의 NotifyIcon
을 사용하므로 System.Windows.Forms.dll
및 System.Drawing.dll
에 대한 참조를 추가하십시오. 또한 트레이 아이콘에 포함 된 리소스를 추가하십시오.
App.xaml
<Application x:Class="WpfTrayIcon.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
ShutdownMode="OnExplicitShutdown"
>
<Application.Resources>
</Application.Resources>
</Application>
App.xaml.cs를
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Windows;
using NotifyIcon = System.Windows.Forms.NotifyIcon;
namespace WpfTrayIcon
{
public partial class App : Application
{
public static NotifyIcon icon;
protected override void OnStartup(StartupEventArgs e)
{
App.icon = new NotifyIcon();
icon.Click += new EventHandler(icon_Click);
icon.Icon = new System.Drawing.Icon(typeof(App), "TrayIcon.ico");
icon.Visible = true;
base.OnStartup(e);
}
private void icon_Click(Object sender, EventArgs e)
{
MessageBox.Show("Thanks for clicking me");
}
}
}
[전용 트레이 아이콘이 WPF 출원 (
의 중복 가능성 http://stackoverflow.com/questions/1472633/wpf-application-that-only-has-a-tray-icon) – svick
이 게시물 확인 http://stackoverflow.com/questions/1472633/wpf-application-that-only-has-a-tray-icon –