2013-03-28 66 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