MessagePrompt在首次启动应用程序时崩溃

时间:2011-12-09 10:09:33

标签: c# .net silverlight windows-phone-7

我有一个问题,我在我的WP7应用程序中使用coding4fun dll来显示弹出消息。 我正在使用:

  1. Micrsoft.Phone.Controls.Toolkit
  2. Coding4fun.Phone.Controls
  3. 首次在设备上启动部署时,崩溃说该值不能为null(参数名称元素),而在模拟器上运行正常。我已经尝试了这个dll的最新版本,但结果是一样的。

    添加最新版本1.4.8的Micrsoft.Phone.Controls.Toolkit时,警告添加silverlight库可能会导致意外后果。

    虽然我尝试了这个dll的其他版本仍然没有成功。

    我在stacktrace

    中遇到异常
    1. Clarity.Phone.Extensions.DialogService.InitializePopUp
    2. Clarity.Phone.Extensions.DilaogService.Show
    3. 基本上我在InitializeComponent()之后在mainpage.xaml(第一页)的constuctor中使用该弹出窗口,并且在部署时首次启动时抛出空引用类型但是安装了app。如果我在设备上运行应用程序然后它正确显示。 我的代码是:

      notificationPrompt = new MessagePrompt();
      notificationPrompt.Title = "Notification"
      notificationPrompt.Body = "";
      notificationPrompt.ActionPopUpButtons.Clear();
      Button btnDisclaimer = new Button() { Content = "Yes" };
      btnDisclaimerContinue.Click += new RoutedEventHandler(btnNotificationPromptYes_Click);
      Button btnDisclaimerCancel = new Button() { Content = "No" };
      btnDisclaimerCancel.Click += new RoutedEventHandler(btnNotificationPromptNo_Click);
      notificationPrompt.ActionPopUpButtons.Add(btnDisclaimerContinue);
      notificationPrompt.ActionPopUpButtons.Add(btnDisclaimerCancel);
      notificationPrompt.Show();
      

1 个答案:

答案 0 :(得分:-1)

我认为最好将所有这些代码移到构造函数之外,并将其放在Loaded事件中(当构造FrameworkElement并将其添加到对象树时发生:http://msdn.microsoft.com/en-us/library/ms596558(vs.95))PhoneApplicationPage类,或者只是覆盖OnNavigatedTo方法:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    base.OnNavigatedTo(e);

    // What you want here...
    ...
}

通常,当您在PhoneApplicationPage的构造函数中有异常时,它们将无法显示,从而使调试更加困难和烦人......

相关问题