Реализовать иконку в system tray можно с помощью NotifyIcon; для этого в References проекта WPF Application надо:
- добавить сборку System.Windows.Forms.dll
- в App.xaml у тега Application убрать атрибут StartupUri
- в App.cs в class App добавить конструктор
public App( ) { // закрытие всех окон приложения не приводит к его завершению this .ShutdownMode = ShutdownMode .OnExplicitShutdown; // создать иконку и поместить ее в system tray var ni = new System .Windows .Forms .NotifyIcon( ) ; ni .Visible = true; ni .Icon = WpfApplication6 .Properties .Resources .Icon1; ni .Click += ( s, _) = > { // создать и показать окно var uri = new Uri( "Window1 .xaml", UriKind .Relative) ; var wnd = Application .LoadComponent( uri) as Window; wnd .Visibility = Visibility .Visible; wnd .ShowInTaskbar = false; }; // определить контекстное меню ni .ContextMenu = new System .Windows .Forms .ContextMenu( new[] { // завершить приложение new System .Windows .Forms .MenuItem( "Exit", delegate { ni .Visible = false; this .Shutdown( ) ; }) }) ; }
Комментариев нет:
Отправить комментарий