问题
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