Can I use NotifyIcon in WPF?

I want to minimize the application in the system tray using WPF. Is "NotifyIcon" the only way to achieve this result? If so, what namespace is required to use "NotifyIcon" in WPF?

If possible with "NotifyIcon", please provide some hint, how can I use this in my Mainwindow?

My main window

public partial class MonthView : MetroWindow { public DateTime SelectedDate { get; set; } public MonthView() { InitializeComponent(); calMain.DisplayDate = DateTime.Today; Globals._globalController = new AppController(); Globals._globalController.appTaskManager.setupLocal(); Globals._globalController.setMonthViewWindow(this); } public void calItemSelectedDate(object sender, SelectionChangedEventArgs e) { DateTime d; if (sender is DateTime) { d = (DateTime)sender; } else { DateTime.TryParse(sender.ToString(), out d); } SelectedDate = d; ShowActivity(d); } public void ShowActivity(DateTime date) { DayView Activity = new DayView(date); Activity.Show(); this.Hide(); } private void SetButton_Click(object sender, RoutedEventArgs e) { SettingsView set = new SettingsView(); set.Show(); this.Hide(); } } 
+7
c # windows wpf wpf-controls notifyicon
source share
3 answers

NotifyIcon is not implemented in WPF since it is in Forms, but you can still use Windows Form NotifyIcon, it is in the System.Windows.Forms namespace.

Take a look at these guides, they can meet your needs:

A simple solution directly using NotifyIcon: http://www.abhisheksur.com/2012/08/notifyicon-with-wpf-applications.html

A more advanced solution, a new NotifyIcon-based library with many features: http://www.codeproject.com/Articles/36468/WPF-NotifyIcon

More information about NotifyIcon can be found here: http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx

+17
source share

Yes, it is possible, and I have successfully used it in my personal project. There is excellent control written by Philip Sumi http://www.hardcodet.net/projects/wpf-notifyicon . I used exactly that one, and it works great and looks beautiful (subjective).

image

Just note: pay attention to the licensing conditions, check if you can use it in your project.

+7
source share

You can set the code for NotifyIcon in App.xaml.cs

 using System.Drawing; namespace DDD { /// <summary> /// Interaction logic for App.xaml /// </summary> public partial class App : Application { System.Windows.Forms.NotifyIcon nIcon = new System.Windows.Forms.NotifyIcon(); public App() { nIcon.Icon = new Icon(@"path to ico"); nIcon.Visible = true; nIcon.ShowBalloonTip(5000, "Title", "Text", System.Windows.Forms.ToolTipIcon.Info); nIcon.Click += nIcon_Click; } void nIcon_Click(object sender, EventArgs e) { //events comes here MainWindow.Visibility = Visibility.Visible; MainWindow.WindowState = WindowState.Normal; } } } 

And in your Mainwindow.xaml.cs:

 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { e.Cancel = true; this.Visibility = Visibility.Hidden; } 

Make sure Window_Closing is bound to the main window close event.

If you “close” your main window, the visibility of the window will be hidden, but your application will work. Just click NotifyIcon in the notification area and your window will return.

+2
source share

All Articles