我正在研究WPF應用程序。其中一個Windows的IsCancel=true
有一個名爲「取消」的按鈕。當用戶單擊取消或按下ESCAPE
鍵時,我需要顯示帶有是/否的消息框。如果用戶單擊是,窗口應該繼續關閉,但如果用戶單擊否,它不應該關閉窗體,但在窗口打開的情況下繼續常規操作。我該怎麼做?請幫忙。提前致謝。WPF取消按鈕
Q
WPF取消按鈕
2
A
回答
3
這將幫助你
void Window_Closing(object sender, CancelEventArgs e)
{
MessageBoxResult result = MessageBox.Show(
"msg",
"title",
MessageBoxButton.YesNo,
MessageBoxImage.Warning);
if (result == MessageBoxResult.No)
{
// If user doesn't want to close, cancel closure
e.Cancel = true;
}
}
3
你可以在WindowClosing
處理它。
看一看here。有一個非常接近你的例子。
1
var Ok = MessageBox.Show("Are you want to Close", "WPF Application", MessageBoxButton.YesNo, MessageBoxImage.Information);
if (Ok == MessageBoxResult.Yes)
{
this.Close();
}
else
{
}
1
打開一個消息框,並宣讀結果像這樣:
DialogResult result = MessageBox.Show(
"Text",
"Title",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
//The user clicked 'Yes'
}
else if (result == DialogResult.No)
{
//The user clicked 'No'
}
else
{
//If the user somehow didn't click 'Yes' or 'No'
}
相關問題
- 1. WPF:取消按鈕動畫
- 2. 取消按鈕
- 3. iPhone取消按鈕
- 4. jqTransform取消按鈕
- 5. JDialog取消按鈕
- 6. 如何「取消」按鈕按?
- 7. Ios:取消高亮取消按鈕
- 8. Javascript提示取消按鈕不「取消」
- 9. Bootstrap Validator.js和取消按鈕
- 10. jeditable取消按鈕回調?
- 11. UISearchBar取消按鈕Xcode 4.3?
- 12. Silverlight關閉/取消按鈕
- 13. Laravel表單按鈕取消
- 14. 點擊取消按鈕showInputDialogue
- 15. UISearchcontroller取消按鈕代理
- 16. UIAlertView無取消按鈕?
- 17. FBDialog取消按鈕回調
- 18. 取消選項組按鈕
- 19. Powershell&取消按鈕或ESC
- 20. Android:DatePickerdialog與取消按鈕
- 21. IAP iOS UIAlertView取消按鈕
- 22. 倒計時取消按鈕
- 23. 取消按鈕使用MBProgressView
- 24. 的UISearchBar取消按鈕
- 25. 啓用通過WPF命令模式提交/取消按鈕
- 26. 取消異步方法的按鈕(wpf - databinding命令)
- 27. 如何在按下取消按鈕時取消部分視圖
- 28. 按取消按鈕不收回
- 29. 如何按下按鈕取消超時?
- 30. remove從本地通知取消按鈕或覆蓋取消按鈕功能
那麼這就是問題!怎麼做'不'? – 2013-04-22 08:40:32
在NO部分是否使用'e.Cancel = True'。 – 2013-04-22 08:42:16
只需將空白選項保留爲空。 – 2013-04-22 08:44:23