6

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

1 回答 1

2

看起来像您正在寻找的东西。对消息框的调用包括一个“所有者”参数。我在以前做过的代码中使用了类似的概念,并将窗口显示为模态。示例代码也可以从链接下载。

于 2012-05-15T11:40:12.873 回答