我可以在WPF中使用NotifyIcon吗? [英] Can I use NotifyIcon in WPF?
问题描述
我想最小化使用WPF到系统托盘的应用程序。是 NotifyIcon是实现此结果的唯一方法吗?如果是,在WPF中使用 NotifyIcon需要哪个命名空间?
I want to minimizing application to system tray using WPF. Is "NotifyIcon" is the only way to achieve this result? If yes, which namespace is required for using "NotifyIcon" in WPF?
如果可以使用 NotifyIcon,请提供一些提示,如何在我的主窗口中使用它?
If possible with "NotifyIcon",please provide some hint, how can I use that in my Mainwindow?
我的主窗口是
public partial class MonthView : MetroWindow
{
public DateTime SelectedDate { get; set; }
public MonthView()
{
InitializeComponent();
calMain.DisplayDate = DateTime.Today;
Globals._globalController = new AppController();
Globals._globalController.appTaskManager.setupLocal();
Globals._globalController.setMonthViewWindow(this);
}
public void calItemSelectedDate(object sender, SelectionChangedEventArgs e)
{
DateTime d;
if (sender is DateTime)
{
d = (DateTime)sender;
}
else
{
DateTime.TryParse(sender.ToString(), out d);
}
SelectedDate = d;
ShowActivity(d);
}
public void ShowActivity(DateTime date)
{
DayView Activity = new DayView(date);
Activity.Show();
this.Hide();
}
private void SetButton_Click(object sender, RoutedEventArgs e)
{
SettingsView set = new SettingsView();
set.Show();
this.Hide();
}
}
推荐答案
NotifyIcon 在WPF中并未像在Forms中那样实现,但是您仍然可以使用Windows Form NotifyIcon ,它位于 System.Windows中。表单 namspace。
NotifyIcon is not implemented in WPF as it is in Forms, but you can still use the Windows Form NotifyIcon, it resides in the System.Windows.Forms namspace.
看看这些教程,它们可能满足您的需求:
Take a look at these tutorials, they might cover your needs:
直接使用NotifyIcon的简单解决方案:
http:// www.abhisheksur.com/2012/08/notifyicon-with-wpf-applications.html
Simple solution, directly using NotifyIcon: http://www.abhisheksur.com/2012/08/notifyicon-with-wpf-applications.html
更多高级解决方案,基于 NotifyIcon的新库具有更多功能:
http://www.codeproject.com / Articles / 36468 / WPF-NotifyIcon
More advanced solution, new library based on NotifyIcon with more features: http://www.codeproject.com/Articles/36468/WPF-NotifyIcon
有关 NotifyIcon 的更多信息,请参见:
http://msdn.microsoft.com/zh-cn/library/system.windows.forms.notifyicon.aspx
More info about NotifyIcon can be found here: http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx
这篇关于我可以在WPF中使用NotifyIcon吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!