简体   繁体   English

Windows Phone 8.1 App不显示MessageDialog

[英]Windows Phone 8.1 App doesn't show MessageDialog

I have a problem concerning the Windows.Ui.Popups.MessageDialog. 我有一个关于Windows.Ui.Popups.MessageDialog的问题。

I am developing a Windows Phone 8.1 App using the Prism framework with Unity and Visual Studio 2013 Community. 我正在使用带有Unity和Visual Studio 2013社区的Prism框架开发Windows Phone 8.1 App。 When I try to show a simple MessageDialog from the ViewModel with code like this: 当我尝试使用如下代码从ViewModel中显示一个简单的MessageDialog时:

var msgDialog = new Windows.Ui.Popups.MessageDialog("Content");
msgDialog.Title = "Title";
var result = await msgDialog.ShowAsync();

nothing happens, no dialog, no output, no error, no exception, nothing. 没有任何反应,没有对话框,没有输出,没有错误,没有异常,没有任何反应。 Same problem occurs when I try to show a MessageDialog from the views code behind file. 当我尝试从文件后面的视图代码显示MessageDialog时,也会发生相同的问题。

It seems that the app simply ignores this lines of code. 看来该应用只是忽略了这行代码。 Otherwise the app works perfectly. 否则,该应用程序将完美运行。

Can anybody help? 有人可以帮忙吗?

First of all Windows.Ui should be Windows.UI and secondly try and use this and see if it helps: 首先, Windows.Ui应该是Windows.UI ,其次尝试并使用它,看看是否有帮助:

public class MessageDialogHelper
    {
        public static async void Show(string content, string title)
        {
            MessageDialog messageDialog = new MessageDialog(content, title);
            await messageDialog.ShowAsync();
        }
    }
public void func1()
{
     MessageDialogHelper.Show("Message","Title");
}

I always write them in one line. 我总是将它们写成一行。 Did you try to debug it and see if it steps into the call. 您是否尝试调试它并查看它是否进入了调用。

Are you running the code from the UI thread. 您是否正在从UI线程运行代码。

Does ShowAsync() have a return value? ShowAsync()是否有返回值?

await new MessageDialog("Content of your message", "Title").ShowAsync();

thank you for your quick respones! 感谢您的快速回复!

I found the solution after a few hours of trial and error. 经过数小时的反复试验,我找到了解决方案。 Finally the only thing I had to do was to reboot my mobile phone. 最终,我唯一要做的就是重启手机。 I can't explain what happened but this solved my problem. 我无法解释发生了什么,但这解决了我的问题。 Now I can see my MessageDialogs as expected. 现在,我可以按预期看到我的MessageDialogs。

Thank you again! 再次感谢你!

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

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