2016-09-28 89 views
-2

我创建了一个WPF应用程序。它有一个窗口,隐藏在关闭按钮上。但我想在通知栏中显示它。当用户点击它时,窗口应该显示。如何显示当前窗口通知栏不隐藏在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

,但没有得到你我该怎么办这个?

任何帮助表示赞赏!

+1

[最小化/关闭应用到使用WPF系统托盘(的可能的复制http://stackoverflow.com/questions/27265139/minimizing-closing-application- to-system-tray-using-wpf) –

+0

@ManfredRadlwimmer,必须阅读我的问题吗?请先阅读。我想在通知中显示 –

+0

是的,我阅读了你的问题。您自己链接的帖子包含您需要的所有信息。如果您对已阅读的答案有进一步的问题 - 您可以在原始答案中添加评论(当您有足够的声望时)并要求澄清。由于您没有包含所需的[MCVE],因此我们无法帮助您达成任何目标。 –

回答

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; 
       };