2012-05-15 27 views
6

我試圖在我的應用程序中顯示一個標準的MessageBox作爲模式窗口,但它最終成爲非模態。 在第一個調用中,在下面的代碼中,我顯示了一個標準的MessageBox,它顯示爲模態,因爲它應該。在第二次調用中,即使我抓取主窗口調度程序,它也不會顯示爲模式。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

爲什麼不使用WPF窗口來自定義消息框? –

+0

我需要更多地學習文檔,默認情況下信息消息框不是默認的,需要設置所有者 – klashagelqvist

回答

2

This看起來像你在找什麼。消息框的調用包括「所有者」參數。我在代碼中使用了類似的概念,並且已經將窗口顯示爲模態。示例代碼也可以從鏈接中下載。