Reputation: 757
I have an issue with the CustomMessageBox from the WP Toolkit. Currently, I have code that launches a prompt for an app rating on every two clicks of a button.
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++;
All options seem to work fine except those that actually launch the MarketplaceReviewTask. The task launches correctly, but on resuming the app I'm hitting a NullReferenceException:
{System.NullReferenceException: NullReferenceException at Microsoft.Phone.Controls.CustomMessageBox.ClosePopup(Boolean restoreOriginalValues) at Microsoft.Phone.Controls.CustomMessageBox.<>c_DisplayClass4.b_1(Object s, EventArgs e) at Microsoft.Phone.Controls.Transition.OnCompleted(Object sender, EventArgs e) at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args) at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)}
How can I fix this? Changing to the MessagePrompt in the Coding4Fun Toolkit is a LAST resort.
Upvotes: 1
Views: 977
Reputation: 1
Got the same issue. There was a bug in the CustomMessageBox.cs. They called popup when it was null.
private void ClosePopup(bool restoreOriginalValues)
{
_popup.IsOpen = false;
It's fixed in the newest version http://phone.codeplex.com
Upvotes: 0
Reputation: 1360
I used a boolean on the dismissed event to define which button had been pressed. I then implemented the code I would of implemented in the dismissed event in the Unloaded event instead. This seemed to solve the issue.
i.e
messageBox.Dismissed += (s1, e1) =>
{
switch (e1.Result)
{
case CustomMessageBoxResult.LeftButton:
{
delete = true ;
}
break;
case CustomMessageBoxResult.RightButton:
break;
case CustomMessageBoxResult.None:
break;
default:
break;
}
};
messageBox.Unloaded += (s1, e1) =>
{
if (delete)
DeleteWorkout();
};
Upvotes: 0
Reputation: 757
I cannot figure this out and it's quite important for me to push out an update, so I have gone ahead and well, "cheated" a little. I've "handled" the exception:
if (e.ExceptionObject.Message.ToString() == "NullReferenceException")
{
e.Handled = true;
return;
}
under Application_UnhandledException
.
If anyone has any better fix for this I'd love to hear it.
Upvotes: 1
Reputation: 30912
I think the problem could be in your Dismissed
handler. I'm not sure how CustomMessageBox
is implemented, but it might be likely that the checkBox
property is null.
Upvotes: 0