Barry Allen
Barry Allen

Reputation: 101

How to display current window to notification bar NOT HIDE in WPF

I've created one WPF application. It has one window and it's hide on close button. But i want to show it in notification-bar. and when user click on that then windows should display.

Here is my code:

public MainWindow()
{
    InitializeComponent();
    System.Timers.Timer aTimer = new System.Timers.Timer();
    aTimer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
    aTimer.Interval = 3000;
    aTimer.Enabled = true;

}

private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    lblProcess.Content = "Test Window"

}

// minimize to system tray when applicaiton is closed
protected override void OnClosing(CancelEventArgs e)
{
    // setting cancel to true will cancel the close request
    // so the application is not closed
    e.Cancel = true;

    this.Hide();
    //this.Show();

    base.OnClosing(e);
}

I've already read this: create-popup-toaster-notifications-in-windows-with-net

And minimizing-application-to-system-tray-using-wpf-not-using-notifyicon

minimizing-closing-application-to-system-tray-using-wpf

But didn't get you how can i do this?

Any help appreciated!

Upvotes: -2

Views: 1257

Answers (1)

Barry Allen
Barry Allen

Reputation: 101

I have done using this code:

System.Windows.Forms.NotifyIcon ni = new System.Windows.Forms.NotifyIcon();
ni.Icon = new System.Drawing.Icon("D:\\images.ico");
ni.Visible = true;
ni.DoubleClick +=delegate(object sender, EventArgs args)
               {
                  this.Show();
                  this.WindowState = WindowState.Normal;
               };

Upvotes: 2

Related Questions