c# - WPF 应用程序中的模式消息框

标签 c# wpf messagebox

我试图在我的应用程序中将标准 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/

相关文章:

c# - 从ViewModel中选择 ListView 中的所有项目

wpf - WPF在 View 中更改ViewModel属性

c++ - DLL_PROCESS_ATTACH 无法在 Windows 7 C++ 上执行

c# - EF : order by 2 fields when they are not null

java - 您可以像在 .NET 中那样在 Java 中创建未定义的枚举值吗?

c# - 无法在 Visual Studio 2012 中调试 Windows 服务

c# - 获取绑定(bind)的父级

c# - Windows Phone 8.1 WinRT 应用程序中的自定义消息框

java - GWT 中的消息框

c# - RichTextBox 水平滚动不起作用