[英]Windows Phone 8.1 Modal Dialog. How?
按照堆栈溢出中的示例,我组合了一个MessageDialog来显示用户错误消息。 在模拟器中,它可以正常工作。
在电话上,它一直闪过,只在屏幕上闪烁了MessageDialog一会儿,甚至还闪过了Task.Delay,我将其作为解决方法。
有人可以向我解释发生了什么,还是指出正确的方向?
ps我也在这里的每篇文章中尝试了ContentDialog。 甚至不显示消息文本。
这是一个代码片段:
public static async void ShowAndGo (String MessCode, String MessText, Boolean Xit)
{
String Mess = ""; // Start out with an empty Message to tell Joe User.
String Title = ""; // And an empty title too.
if (MessCode != "") // If we're sent a Message "Code,"
Mess = App.ResLdr.GetString (MessCode) + Cx.ld + Cx.ld; // turn it into text, culturally-aware.
Mess += MessText; // Stick MessText onto the end of it.
if (Xit)
Title = App.ResLdr.GetString ("OhSnap"); // If we're goin' down, curse a little.
else
Title = App.ResLdr.GetString ("NoProb"); // If it's just informational, no problem-o.
MessageDialog messageDialog = new MessageDialog (Mess, Title);
await messageDialog.ShowAsync (); // IT FREAKING ISN'T STOPPING HERE!!!
Task.Delay (10000).Wait (); // Wait 10 seconds with error message on the screen.
// AND IT FREAKING DOESN'T STOP HERE EITHER!!!
}
问题的原因很简单-声明了异步无效方法-避免这种情况,只应在特殊情况下使用,例如事件。 在您拥有的代码中,您的程序不会在调用该方法的地方停下来:
ShowAndGo("Message code", "Message Text", false);
Debug.WriteLine("Something happening");
它可能显示一条消息,但是它将持续多久取决于您的进一步代码。 解决办法是将方法从void更改为Task并等待 :
public static async Task ShowAndGo (String MessCode, String MessText, Boolean Xit)
{ /* method */ }
//invoke:
await ShowAndGo("Message code", "Message Text", false);
Debug.WriteLine("Something happening"); // now it should wait till user clicks OK
当然, 一路需要异步 ,但这可能就是程序的外观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.