PopUpResult

Jul 7, 2012 at 6:00 PM
Edited Jul 7, 2012 at 6:03 PM

How do I assign the PopUpResult to custom buttons?    When I use the code below e.PopUpResult is always cancelled in messagePrompt_Completed event.  Thank you.

        private void PhoneApplicationPage_BackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (messagePrompt == null || !messagePrompt.IsOpen)
            {
                e.Cancel = true;

                messagePrompt = new MessagePrompt();
                messagePrompt.Message = "Do you want to continue or quit the current game.";
                messagePrompt.ActionPopUpButtons.Clear();
                Button quitButton = new Button() { Content = "Quit Game" };
                quitButton.Height = 80;
                quitButton.Width = 200;

                quitButton.Style = (Style)App.Current.Resources["ButtonStyle2"];
                quitButton.Click += new RoutedEventHandler(quitButton_Click);

                Button continueButton = new Button() { Content = "Continue Game" };
                continueButton.Height = 80;
                continueButton.Width = 240;
                continueButton.Style = (Style)App.Current.Resources["ButtonStyle2"];
                continueButton.Click += new RoutedEventHandler(continueButton_Click);
                messagePrompt.ActionPopUpButtons.Add(continueButton);
                messagePrompt.ActionPopUpButtons.Add(quitButton);
                messagePrompt.Completed += messagePrompt_Completed;
                messagePrompt.Show();

            }

            base.OnBackKeyPress(e);
           
        }

        void messagePrompt_Completed(object sender, PopUpEventArgs<string, PopUpResult> e)
        {
            if (e.PopUpResult == PopUpResult.Ok)
            {
                // user hit continue button
            }
            else
            {
                // user hit quit or back button
            }
        }
Coordinator
Jul 7, 2012 at 6:40 PM
OnComplete is a public virtual so you can override it / directly call it.  The sample application has a sample of doing just this.

private void MessageSuperClick(object sender, RoutedEventArgs e)
        {
            var messagePrompt = new MessagePrompt
                                    {
                                        Title = "Advanced Message",
										Background = _naturalBlueSolidColorBrush,
										Foreground = _aliceBlueSolidColorBrush,
										Overlay = _cornFlowerBlueSolidColorBrush,
                                    };

            var btnHide = new RoundButton { Content = "Hide" };
            btnHide.Click += (o, args) => messagePrompt.Hide();

            var btnComplete = new RoundButton { Content = "Complete" };
            btnComplete.Click += (o, args) => messagePrompt.OnCompleted(new PopUpEventArgs<string, PopUpResult> { PopUpResult = PopUpResult.Ok, Result = "You clicked the Complete Button" });

            messagePrompt.ActionPopUpButtons.Clear();
            messagePrompt.ActionPopUpButtons.Add(btnHide);
            messagePrompt.ActionPopUpButtons.Add(btnComplete);

            messagePrompt.Completed += PopUpPromptStringCompleted;

            messagePrompt.Show();
        }