【发布时间】:2013-01-04 06:04:25
【问题描述】:
我对 WP Toolkit 中的 CustomMessageBox 有疑问。目前,我的代码会在每两次单击按钮时启动应用评分提示。
Dispatcher.BeginInvoke(() =>
{
if (rtcount == 2 && (AppSettings.ShowAgainSetting == true))
{
CheckBox checkBox = new CheckBox()
{
Content = "Do not ask me again",
Margin = new Thickness(0, 14, 0, -2)
};
TiltEffect.SetIsTiltEnabled(checkBox, true);
CustomMessageBox messageBox = new CustomMessageBox()
{
Caption = "Would you like to rate and review this application?",
Message =
"Thank you for using my app."
+ Environment.NewLine + Environment.NewLine
+ "If you've been enjoying the app we'd love if you could leave us a rating in the Store. Would you mind spending a couple of seconds to rate (and/or) review this application?",
Content = checkBox,
LeftButtonContent = "ok",
RightButtonContent = "not now",
};
messageBox.Dismissed += (s1, e1) =>
{
switch (e1.Result)
{
case CustomMessageBoxResult.LeftButton:
if ((bool)checkBox.IsChecked)
{
MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
marketplaceReviewTask.Show();
AppSettings.ShowAgainSetting = false;
}
else
{
MarketplaceReviewTask marketplaceReviewTask = new MarketplaceReviewTask();
marketplaceReviewTask.Show();
}
break;
case CustomMessageBoxResult.RightButton:
if ((bool)checkBox.IsChecked)
{
AppSettings.ShowAgainSetting = false;
}
else
{
}
break;
case CustomMessageBoxResult.None:
if ((bool)checkBox.IsChecked)
{
AppSettings.ShowAgainSetting = false;
}
else
{
}
break;
default:
break;
}
};
messageBox.Show();
rtcount = 0;
}
});
rtcount++;
除了实际启动 MarketplaceReviewTask 的选项外,所有选项似乎都可以正常工作。任务正确启动,但在恢复应用程序时我遇到了 NullReferenceException:
{System.NullReferenceException: NullReferenceException 在 Microsoft.Phone.Controls.CustomMessageBox.ClosePopup(布尔 restoreOriginalValues) 在 Microsoft.Phone.Controls.CustomMessageBox.c_DisplayClass4.b_1(Object s, EventArgs e) 在 Microsoft.Phone.Controls.Transition.OnCompleted(对象发送者,EventArgs e) 在 MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex,委托 handlerDelegate,对象发送者,对象参数) 在 MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)}
我该如何解决这个问题?更改为 Coding4Fun Toolkit 中的 MessagePrompt 是最后的手段。
【问题讨论】:
-
似乎在您的 CustomMessageBox 类的 ClosePopup 方法中发生了一些事情。我们需要这些来调试。
-
@Destrictor 显然是 WP Toolkit 的一部分,但我没有它的代码:(
-
Windows Phone Toolkit(适用于 WP7/7.1)的源代码可在 codeplex (silverlight.codeplex.com/releases/view/94435) 上获得。这是 CustomMessageBox.cs 的链接:silverlight.codeplex.com/SourceControl/changeset/view/…
标签: c# windows-phone-7 windows-phone-8 windows-phone nullreferenceexception