我想使用 WPF 将应用程序最小化到系统托盘。 “NotifyIcon”是实现此结果的唯一方法吗?如果是,在 WPF 中使用“NotifyIcon”需要哪个命名空间?
如果可以使用“NotifyIcon”,请提供一些提示,我如何在主窗口中使用它?
我的主窗口是,
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 不像在 Forms 中那样在 WPF 中实现,但您仍然可以使用 Windows Form NotifyIcon,它位于 System.Windows 中。形成 namspace。
看看这些教程,它们可能满足您的需求:
简单的解决方案,直接使用NotifyIcon: http://www.abhisheksur.com/2012/08/notifyicon-with-wpf-applications.html
更高级的解决方案,基于 NotifyIcon 的新库具有更多功能: http://www.codeproject.com/Articles/36468/WPF-NotifyIcon
有关 NotifyIcon 的更多信息可在此处找到: http://msdn.microsoft.com/en-us/library/system.windows.forms.notifyicon.aspx
关于c# - 我可以在 WPF 中使用 NotifyIcon 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17674761/