2016-09-28 86 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; 
       };