简体   繁体   中英

Windows Phone 8.1 App doesn't show MessageDialog

I have a problem concerning the Windows.Ui.Popups.MessageDialog.

I am developing a Windows Phone 8.1 App using the Prism framework with Unity and Visual Studio 2013 Community. When I try to show a simple MessageDialog from the ViewModel with code like this:

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.

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:

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.

Does ShowAsync() have a return value?

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.

Thank you again!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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