Windowless tray icon application

我怕爱的太早我们不能终老 提交于 2019-12-07 17:20:24

问题


OK I am a total newbie at WPF but I have to develop what's in the title with wpf but not relying on MVVM. I have followed this:

WPF Application that only has a tray icon

I found the first answer the one with the hardcodet lib but find it too difficult and MVVM biased.

So followed the second one and everything seemed fine except that in the end it doesn't work. So in my App.xaml.cs I have put:

public partial class App : Application
{
    private System.Windows.Forms.NotifyIcon notifyIcon = null;

    protected override void OnStartup(StartupEventArgs e)
    {
      base.OnStartup(e);
      UnityCore.Initialize();
    }

    protected override void OnActivated(EventArgs e)
    {
      notifyIcon = new System.Windows.Forms.NotifyIcon();
      notifyIcon.Click += NotifyIcon_Click;
      notifyIcon.DoubleClick += NotifyIcon_DoubleClick;

      Stream iconStream = Application.GetResourceStream(new Uri("pack://application:,,,/Resources/Images/ITA.png")).Stream;
      notifyIcon.Icon = new System.Drawing.Icon(iconStream);
      notifyIcon.Visible = true;
      base.OnActivated(e);
    }

    private void NotifyIcon_DoubleClick(object sender, EventArgs e)
    {
      Console.Beep();//show main window
    }

    private void NotifyIcon_Click(object sender, EventArgs e)
    {
      Console.Beep();//show main window
    }
}

The main window at start is transparent of minimized to make it invisible.

At this stage I hoped to see the ITA flag in the tray icon and then at click or double click restore the main window.

But I don't see a damn thing in the tray.

I think that the flag resource is properly set here's my solution

Thanx for any help.

来源:https://stackoverflow.com/questions/34316894/windowless-tray-icon-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!