[英]C# WPF-Ask user before closing application if right-clicking the application icon on the system task bar
假設我單擊應用程序中的關閉按鈕,它將彈出一個對話框,顯示是和否選項。 如果我通過右鍵單擊系統任務欄上的應用程序圖標來關閉應用程序,該如何實現(彈出對話框詢問用戶是否要關閉該應用程序)?
在您的MainWindow中訂閱關閉事件:
public MainWindow()
{
InitializeComponent();
Closing += OnClosing;
}
private void OnClosing(object sender, CancelEventArgs cancelEventArgs)
{
if (MessageBox.Show(this, "Your message", "Confirm", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
{
cancelEventArgs.Cancel = true;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.