简体   繁体   English

如何在 C# ion WP7 中显示来自 static 方法的 MessageBox?

[英]How to show a MessageBox from a static method in C# ion WP7?

I have a Page on Windows Phone that is called asynchronously, from which I want to show a MessageBox.我在 Windows 电话上有一个页面,它被异步调用,我想从中显示一个 MessageBox。 I would normally:我通常会:

this.Dispatcher.BeginInvoke(() => MessageBox.Show("The message"));

but this doesn't quite work in a static method.但这在 static 方法中不太适用。

How do I get the MessageBox to display from a static method?如何让 MessageBox 从 static 方法显示?

You can access the UI dispatcher using Application.Current.RootVisual.Dispatcher :您可以使用Application.Current.RootVisual.Dispatcher访问 UI 调度程序:

Dispatcher dispatcher = Application.Current.RootVisual.Dispatcher;
dispatcher.BeginInvoke(() => MessageBox.Show("The message"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM