title: Minimizing/Closing Application to system tray using WPF
body: <p>I want to add application in System Tray when user minimize or close the form. I have done it for the Minimize case. Can anyone tell me that how i can keep my app running and add it into System Tray when I close the form?</p>
  
  <pre><code>public MainWindow()
      {
          InitializeComponent();
          System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
          ni.Icon = new System.Drawing.Icon(Helper.GetImagePath("appIcon.ico"));
          ni.Visible = true;
          ni.DoubleClick +=
              delegate(object sender, EventArgs args)
              {
                  this.Show();
                  this.WindowState = System.Windows.WindowState.Normal;
              };
          SetTheme();
      }
  
      protected override void OnStateChanged(EventArgs e)
      {
          if (WindowState == System.Windows.WindowState.Minimized)
              this.Hide();
          base.OnStateChanged(e);
      }
  </code></pre>