Modal MessageBox in a WPF Application

I am trying to show a standard MessageBox as a modal window in my application, but it ends up as non-modal. In the first call, in the code below, I show the standard MessageBox, which appears modal, as it should be. In the second call, it does not appear as modal, even if I grab the main window manager.

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(); } } 
+6
source share
1 answer

It looks the way you are looking. The call for the message box includes the owner parameter. I used a similar concept in code that I made earlier and showed that windows are modal. Sample code can also be downloaded from the link.

+2
source

Source: https://habr.com/ru/post/915771/


All Articles