1
votes

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.

4
Seems like something is happening in the ClosePopup method of your CustomMessageBox class. We'll need those to debug.Destrictor
@Destrictor that is apparently part of the WP Toolkit though, I don't have the code for it :(ReignOfComputer
The source code of the Windows Phone Toolkit (for WP7/7.1) is available on codeplex (silverlight.codeplex.com/releases/view/94435). Here is a link to the CustomMessageBox.cs: silverlight.codeplex.com/SourceControl/changeset/view/…Volker Voecking

4 Answers

1
votes

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.

0
votes

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.

0
votes

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();
        };
0
votes

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