【问题标题】:How to display current window to notification bar NOT HIDE in WPF如何在 WPF 中不隐藏通知栏显示当前窗口
【发布时间】:2016-09-28 08:57:11
【问题描述】:

我创建了一个 WPF 应用程序。它有一个窗口,它隐藏在关闭按钮上。但我想在通知栏中显示它。当用户点击它时,应该会显示窗口。

这是我的代码:

public MainWindow()
{
    InitializeComponent();
    System.Timers.Timer aTimer = new System.Timers.Timer();
    aTimer.Elapsed += new ElapsedEventHandler(Timer_Elapsed);
    aTimer.Interval = 3000;
    aTimer.Enabled = true;

}

private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
    lblProcess.Content = "Test Window"

}

// minimize to system tray when applicaiton is closed
protected override void OnClosing(CancelEventArgs e)
{
    // setting cancel to true will cancel the close request
    // so the application is not closed
    e.Cancel = true;

    this.Hide();
    //this.Show();

    base.OnClosing(e);
}

我已经读过这个:create-popup-toaster-notifications-in-windows-with-net

还有minimizing-application-to-system-tray-using-wpf-not-using-notifyicon

minimizing-closing-application-to-system-tray-using-wpf

但没明白我该怎么做?

任何帮助表示赞赏!

【问题讨论】:

  • @ManfredRadlwimmer,必须阅读我的问题吗?请先阅读。我想在通知中显示这个
  • 是的,我读到了你的问题。您自己链接的帖子包含您需要的所有信息。如果您对已阅读的答案还有其他问题 - 您可以在原始答案中添加评论(当您有足够的声誉时)并要求澄清。由于您没有提供所需的minimal reproducible example,因此我们无法为您提供更多帮助。
  • @ManfredRadlwimmer,它即将隐藏窗口,我做到了,我想要通知

标签: c# wpf notification-bar


【解决方案1】:

我已经使用了这个代码:

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

【讨论】:

    猜你喜欢
    • 2010-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 2012-12-27
    • 2013-10-21
    • 1970-01-01
    相关资源
    最近更新 更多