我正在尝试在我的应用程序中将标准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();
}
}