[英]Windows Phone - Store Universal App MessageDialog on launch
I want to show messagedialog when app starts. 我想在应用启动时显示messagedialog。 But in Universal app this code won't work.
但是在通用应用中,此代码无法正常工作。 I want to ask user for review.
我想请用户进行审查。
Windows.Storage.ApplicationDataContainer localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
var composite = localSettings.Values["askforreview"];
if (composite == null)
{
localSettings.Values.Add("askforreview", true);
composite = true;
}
bool askforreview = Convert.ToBoolean(composite);
if (askforreview)
{
MessageDialog dialog = new MessageDialog("some message");
dialog .Commands.Add(new UICommand("Yes", ( command) =>
{
Launcher.LaunchUriAsync(CurrentApp.LinkUri);
}));
dialog.Commands.Add(new UICommand("Not Now"));
await dialog .ShowAsync();
}
When I debug app, I always get an error "a.ShowAsnyc" statement. 当我调试应用程序时,我总是收到错误“ a.ShowAsnyc”语句。 Program stops in App.gics's this statement.
程序在App.gics的此语句中停止。
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
This type of exception (UnauthorizedAccessException - Access Denied) when it comes to MessageDialogs usually happens when you already have one MessageDialog opened when you try to open another one. 当涉及到MessageDialogs时,这种类型的异常(UnauthorizedAccessException-访问被拒绝)通常发生在当您尝试打开另一个MessageDialog时已经打开了一个MessageDialog时。
I was able to get your code to work on my side in both page constructor (without the await, though), and in page loaded async event handler. 我能够使您的代码在页面构造函数(尽管没有等待)和页面加载的异步事件处理程序中都能正常工作。 But if I tried to do it in two places one after another, it would throw an exception, for the reason mentioned above.
但是,如果我试图一个接一个地在两个地方进行操作,则由于上述原因,它将引发异常。
So, please check that you don't have another MessageDialog opened when you try to show this one. 因此,请在尝试显示该对话框时,确保没有打开另一个MessageDialog。 Did you perhaps leave this code in both the page constructor and the app launched event handler?
您是否可能将此代码保留在页面构造函数和应用程序启动的事件处理程序中? That might cause it.
那可能会导致它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.