27

I am finished making my application and now I want to incorporate " minimizing into the system tray feature " for it . I read up a good article minimize app to system tray . I realized that these make use of the Windows.Form class .

Unfortunately I have used Windows Presentation Foundation WPF reference to make my applications UI . Now I see that the NotifyIcon is not supported in WPF. I see that there is an open source library on CodePlex that simulates the NotifyIcon properties WPF Contrib I have not used it as yet .

Now I am in a fix . Here are my questions :-

a) I don't want to incorporate a 3'rd party library just for one single component .

b) Can I do the minimizing feature without NotifyIcon on WPF? If yes then how can someone give me leads please ?

Or maybe I should revert my UI back to using Windows Forms ?

Community
  • 1
  • 1
rockstar
  • 3,512
  • 6
  • 40
  • 63
  • Edit your post; try to add links like this [link text](http:/.......com). –  Feb 05 '13 at 05:16

3 Answers3

32

If you'll reconsider your reluctance to using an external component, I recommend WPF NotifyIcon. I've used it. It's straightforward and works well.

It does not just rely on the corresponding WinForms component, but is a purely independent control which leverages several features of the WPF framework in order to display rich tooltips, popups, context menus, and balloon messages.

akjoshi
  • 15,374
  • 13
  • 103
  • 121
Marksl
  • 822
  • 8
  • 15
  • Thanks @Marksl : Good to know that it is stable and working well for you . I will wait for someother people to throw in their views . Or if they have any other suggestions . – rockstar Feb 05 '13 at 05:27
  • For my project, I was planning on merging all assemblies together with ILMerge. In the end WPF NotifyIcon was so small, I just copied the code directly in the project - perhaps not best practice, but it was quick. There's really not much code to it. I'm interested to see if there are other approaches too. – Marksl Feb 05 '13 at 05:31
  • I have also used this in my project and works well. You can strip the code which you don't need and just add the minimal required code into your application. I also tried a lot of things at that time and this was the best possible solution. – akjoshi Feb 07 '13 at 06:37
  • @akjoshi . Thanks for your valueable inputs . I will consider using it in my application . – rockstar Feb 08 '13 at 02:41
  • 4
    It's also available through [NuGet](https://www.nuget.org/packages/Hardcodet.NotifyIcon.Wpf/) – mack Jan 07 '14 at 19:59
  • Bad news for the future though, it doesn't seem to be totally DPI aware. On high DPI monitors it looks like it doesn't correctly place the pop-up menu. – Joel Barsotti Jan 15 '16 at 00:20
2

I just came across this post today.

For reference, I also solved this some time back. It works very well and the only time I have had a bit of an issue is occasionally on some multi-display set ups.

This was before GITs and NuGets were the in-thing, I will place it in a GIT repo if there is interest.

CodeProject Article Here

Murray Foxcroft
  • 12,785
  • 7
  • 58
  • 86
-1

Solution with System.Windows.Forms.NotifyIcon

Here is a thread , which helped me a lot .

https://stackoverflow.com/a/12428063/10305444

public partial class Window : System.Windows.Window{


public Window()
{
    InitializeComponent();

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

protected override void OnStateChanged(EventArgs e)
{
    if (WindowState == WindowState.Minimized)
        this.Hide();

    base.OnStateChanged(e);
}}
Maifee Ul Asad
  • 3,992
  • 6
  • 38
  • 86