2013-03-28 67 views
1

我正在Windows Phone 8上開發一個應用程序,我想問一下在MessageBox被包裝在Deployment.Current.Dispatcher.BeginInvoke中時,是否有任何方法從MessageBox.Show中獲取結果?例如:如何從Deployment.Current.Dispatcher.BeginInvoke獲取結果?

Deployment.Current.Dispatcher.BeginInvoke(() => 
      { 
       MessageBox.Show(message, title, MessageBoxButton.OKCancel); 
      }); 

我想獲得用戶的選擇,我該怎麼做?非常感謝!

回答

4

最好的辦法就是要做到這一點是使用沿結果

Deployment.Current.Dispatcher.BeginInvoke(() => { 
    var result = MessageBox.Show(message, title, MessageBoxButton.OKCancel); 
    OnMessageBoxComplete(result); 
}); 

void OnMessageBoxComplete(MessageBoxResult result) { 
    ... 
} 
+0

感謝JaredPar傳遞迴呼。我使用SycnInvokeHelper將其轉換爲同步呼叫。 – codewarrior

+0

內部類SyncInvokeHelper { 公共無效調用() { 如果(this.dispatcher.CheckAccess()== TRUE){ this.Execute(); } else { this.dispatcher.BeginInvoke(new ExecuteBody(this.Execute)); } } private void Execute() this.Result = this.execBody.DynamicInvoke(args); (this.Completed!= null) { this.Completed(this);如果(this.Completed!= null) { this.Completed(this); } } } – codewarrior