简体   繁体   English

Windows Phone-启动时存储通用应用程序MessageDialog

[英]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.

相关问题 MessageDialog在调用时崩溃-Windows Phone Store应用 - MessageDialog crashes when called - Windows Phone Store app 通用应用程序NTLM适用于Windows应用商店,但不适用于Windows Phone - Universal App NTLM working for Windows Store, but not Windows Phone 如何在Windows Phone 8.1通用商店应用中正确导航后退堆栈 - How to properly navigate backstack in Windows Phone 8.1 universal store app 在Windows Phone 8.1 Universal Store App中触发警报? - Trigger the Alarm in Windows Phone 8.1 Universal Store App? Windows Phone 8.1 App不显示MessageDialog - Windows Phone 8.1 App doesn't show MessageDialog UWP - MessageDialog 在 Windows Phone 和平板电脑模式下使应用程序崩溃 - UWP - MessageDialog crashes the app on Windows Phone and tablet mode 在Windows应用商店中从app.xaml.cs显示MessageDialog - Show MessageDialog from app.xaml.cs in Windows Store app Windows Phone 8.1到Universal App - Windows phone 8.1 to Universal App C#XAML Windows应用商店中带有文本框的InputDialog / MessageDialog - InputDialog/MessageDialog with a textbox in C# XAML Windows store app 更改MessageDialog内容或从MessageDialog处理程序Windows Store应用显示新内容 - change MessageDialog content or show new one from MessageDialog handler Windows Store app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM