我正在编写一个应用程序 (c# + wpf),其中所有模态样式对话框都作为 UserControl
在覆盖主 Window
的半透明网格之上实现。这意味着只有一个 Window
,它保持所有公司应用程序的外观。
要显示一个MessageBox
,语法如下:
CustomMessageBox b = new CustomMessageBox("hello world");
c.DialogClosed += ()=>
{
// the rest of the function
}
// this raises an event listened for by the main window view model,
// displaying the message box and greying out the rest of the program.
base.ShowMessageBox(b);
如您所见,与经典的 .NET 版本相比,不仅执行流程实际上是颠倒的,而且冗长得可怕:
MessageBox.Show("hello world");
// the rest of the function
我真正想要的是一种在对话框关闭事件被引发之前不从 base.ShowMessageBox
返回的方法,但我看不出如何在没有它的情况下等待它挂起 GUI 线程,从而阻止用户单击“确定”。我知道我可以将委托(delegate)函数作为 ShowMessageBox
函数的参数,这可以防止执行反转,但仍然会导致一些疯狂的语法/缩进。
我是否遗漏了一些明显的东西,或者是否有标准的方法来做到这一点?
最佳答案
关于c# - 模拟 ShowDialog 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1826781/