我试图在我的应用程序中将标准 MessageBox 显示为模态窗口,但它最终显示为非模态。 在第一次调用中,在下面的代码中,我显示了一个标准的 MessageBox,它应该是模态显示的。在第二个调用中,即使我捕获了主窗口调度程序,它也没有显示为模态。
Dispatcher disp = Application.Current.MainWindow.Dispatcher;
//First call, shown MODAL
if (this.messageService.ShowYesNo("Do you want to update the Word document, this will regenerate inspectiondata for document", "") == MessageBoxResult.Yes)
{
using (new WaitCursor())
{
_eventAggregator.GetEvent<ProgressBarRequestShow>().Publish("");
worker = new BackgroundWorker();
worker.DoWork += delegate(object s, DoWorkEventArgs args)
{
AITUpdateProgressDelegate update = new AITUpdateProgressDelegate(UpdateProgress);
this.docService.UpdateWorddocument(this.docService.GetCurrentDocumentFilePath, update);
};
worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
try
{
// Second call NOT MODAL
disp.Invoke((Action)delegate()
{
this.messageService.ShowInformation("Document generated, choose Open in Word in main toolbar to show document", "");
});
_eventAggregator.GetEvent<ProgressBarRequestHide>().Publish("");
}
finally
{
}
};
worker.RunWorkerAsync();
}
}
最佳答案
This看起来像你要找的东西。对消息框的调用包括一个“所有者”参数。我在我以前做过的代码中使用了类似的概念,并将窗口显示为模态。也可以从链接下载示例代码。
关于c# - WPF 应用程序中的模式消息框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10597783/