2012-05-15 15 views
6

Sto provando a mostrare un MessageBox standard come una finestra modale nella mia applicazione, ma finisce come non modale. Nella prima chiamata, nel codice qui sotto sto mostrando un MessageBox standard che è mostrato modale, come dovrebbe. Nella seconda chiamata, non viene mostrato come modale, anche se prendo il dispatcher della finestra principale.MessageBox modale nell'applicazione WPF

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(); 
    } 
} 
+0

perché non utilizzare WPF Window per creare messagebox personalizzate? –

+0

Ho bisogno di studiare la documentazione un po 'di più, una messagebox di informazioni non è modale per impostazione predefinita, è necessario impostare il proprietario – klashagelqvist

risposta

2

This sembra quello che stai cercando. La chiamata per la finestra di messaggio include un parametro "proprietario". Ho usato un concetto simile nel codice che ho fatto prima e ha mostrato le finestre come modali. Il codice di esempio può anche essere scaricato dal link.