1

我对 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++;

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)}

我怎样才能解决这个问题?更改为 Coding4Fun Toolkit 中的 MessagePrompt 是最后的手段。

4

4 回答 4

1

我无法弄清楚这一点,推出更新对我来说非常重要,所以我继续前进,并且“被骗”了一点。我已经“处理”了异常:

if (e.ExceptionObject.Message.ToString() == "NullReferenceException")
        {
            e.Handled = true;
            return;
        }

Application_UnhandledException

如果有人对此有更好的解决方法,我很想听听。

于 2013-01-21T13:11:07.530 回答
0

我认为问题可能出在您的Dismissed处理程序中。我不确定如何CustomMessageBox实现,但该checkBox属性可能为空。

于 2013-01-21T07:57:17.433 回答
0

遇到了同样的问题。CustomMessageBox.cs 中有一个错误。当它为空时,他们调用了弹出窗口。

private void ClosePopup(bool restoreOriginalValues)
{
    _popup.IsOpen = false;

它已在最新版本中修复http://phone.codeplex.com

于 2013-10-08T17:28:05.210 回答
0

我在驳回事件上使用了一个布尔值来定义按下了哪个按钮。然后我实现了我将在 Unloaded 事件中的被解雇事件中实现的代码。这似乎解决了这个问题。

IE

        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();
        };
于 2013-06-18T21:40:39.000 回答