如何从 App.xaml.cs 运行 MessageBox.Show()
我可以从 App.xaml.cs 运行 MessageBox.Show() 吗,以便它显示在当前页面上。请提供此解决方案或其他解决方案的一些代码。我需要显示一些与整个应用程序相关的系统消息。
Can I run MessageBox.Show() from App.xaml.cs, so it is shown on current page. Please provide some code to this solution, or some other solution. I need to show some system message which is relevant for whole application.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
不确定,但这行不通吗?
您还可以使用 App.xaml.cs 中提供的导航数据来确定当前页面并在该页面上执行。
我想无论你想出什么,应用程序都需要处于稳定状态,当你处理(未处理的)异常时,你可能无法做到这一点。您应该告诉我们更多信息,以便我们了解您为什么要这样做。如果您必须从 App.xaml.cs 调用 MessageBox.Show,则您的设置似乎有问题
Not sure, but would this not work?
You could also use the navigation data that is available in App.xaml.cs to determine the current Page and execute on that page.
I guess whatever you come up with, the app needs to be in a stable state, you probably can't do this when your handling (unhandled) exception. You should tell us a bit more so we understand why you want to do this. It seems that seomthing is wrong with your setup if you have to call MessageBox.Show from App.xaml.cs
一个简单的方法是...
然后从窗口或应用程序的任何其他部分...
由于“ShowBox”方法是静态的,因此您可以从任何地方调用它。当然,不用说,这并不是真正的“最干净”或最强大的方法,但它会起作用。
A simple approach would be...
And then from a window, or any other part of your application...
Since the 'ShowBox' method is static, you can just call into it from anywhere. Of course it goes without saying that this isn't really the 'cleanest' or most robust approach, but it will work.
我从您的问题中了解到,您正在寻找一种方法,当应用程序中其他地方发生某些事件时,显示来自 App.xaml.cs 的消息。
您可以使用 App.xaml.cs 实现观察者模式,为可能由您的自定义页面触发的事件注册。
话虽如此,从长远来看,我建议您使用消息传递框架来实现此目的。大多数MVVM 框架都带有消息传递框架。它们易于使用,没有或很少有学习曲线。
还有很多这样的框架。
What I understood from your question is you are looking for a way to display message from App.xaml.cs when some event occurs else where in your application.
You can have observer pattern implemented with App.xaml.cs registered for an event which may be triggered by your custom page.
Having said that, in long run I suggest you to use messaging framework for this purpose. Most of the MVVM frameworks come with messaging framework. They are easy to use with no or little learning curve.
there are many more such frameworks.
我使用了此链接的摘录 http:// /www.c-sharpcorner.com/UploadFile/c25b6d/message-dialog-in-windows-store-apps/
I used this extract from this link http://www.c-sharpcorner.com/UploadFile/c25b6d/message-dialog-in-windows-store-apps/
对其他解决方案没有运气,发现:
适用于 Windows Phone 8.1,用于从 App.xaml.cs 调用 MessageDialog 到 ui 线程。
Had no luck with the other solutions, found:
Works on windows phone 8.1 for calling a MessageDialog to ui thread from App.xaml.cs.