我正在编写一个应用程序(c# + wpf),其中所有模式样式对话框都实现为UserControl
覆盖 main 的半透明网格顶部Window
。这意味着只有一个Window
,它保持所有公司应用程序的外观和感觉。
要显示 a 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 线程的情况下等待这个,从而阻止用户单击 OK。我知道我可以将委托函数作为函数的参数,这种ShowMessageBox
函数可以防止执行反转,但仍然会导致一些疯狂的语法/缩进。
我错过了一些明显的东西还是有标准的方法来做到这一点?