locked
Message Dialog default value incorrect when dismissed by charms menu

    Question

  • In the "Message Dialog Sample" the default value is incorrect when the charms menu is opened.

    Here's the code from the sample. To recreate, open the charms menu while the message dialog is in view. Notice the return value is 0, and the expected value is 1.

            /// <summary>
            /// Click handler for the 'CompletedCallbackButton' button.
            /// Demonstrates the use of a message dialog with custom commands and using a completed callback instead of delegates.
            /// A message will be displayed indicating which command was invoked on the dialog.
            /// In this scenario, 'Install updates' is selected as the default choice.
            /// </summary>
            /// <param name="sender">The Object that caused this event to be fired.</param>
            /// <param name="e">State information and event data associated with the routed event.</param>
            private async void CompletedCallbackButton_Click(object sender, RoutedEventArgs e)
            {
                // Create the message dialog and set its content and title
                var messageDialog = new MessageDialog("New updates have been found for this program. Would you like to install the new updates?", "Updates available");

                // Add commands and set their command ids
                messageDialog.Commands.Add(new UICommand("Don't install", null, 0));
                messageDialog.Commands.Add(new UICommand("Install updates", null, 1));

                // Set the command that will be invoked by default
                messageDialog.DefaultCommandIndex = 1;

                // Show the message dialog and get the event that was invoked via the async operator
                var commandChosen = await messageDialog.ShowAsync();

                // Display message showing the label and id of the command that was invoked
                rootPage.NotifyUser("The '" + commandChosen.Label + "' (" + commandChosen.Id + ") command has been selected.", NotifyType.StatusMessage);
            }

    Monday, November 17, 2014 2:53 PM

Answers

  • That sounds like the right behavior. You're canceling the dialog in step 4 so you should get the cancel command rather than the default command.
    Monday, November 17, 2014 4:40 PM
    Owner

All replies

  • Can you please explain the repro steps and your expectations? It sounds like you're getting a legitimate cancel rather than an accepted command.

    Monday, November 17, 2014 3:46 PM
    Owner
  • Step 1: Download the Message Dialog Sample in C#

    Step 2: Put a breakpoint on line #53 in the file "CompletedCallback.xaml.cs"

     // Display message showing the label and id of the command that was invoked
                rootPage.NotifyUser("The '" + commandChosen.Label + "' (" + commandChosen.Id + ") command has been selected.", NotifyType.StatusMessage);

    Step 3: run the program. In exercise 3, click the button "Launch the Dialog."

    Step 4: With the dialog open, open the charms menu by swiping in from the right. Open the settings menu.

    Step 5: Notice the commandChosen.Label is not the default. But the default was set to 1.

                 // Set the command that will be invoked by default
                messageDialog.DefaultCommandIndex = 1;


    • Edited by Bryan Stump Monday, November 17, 2014 4:02 PM
    Monday, November 17, 2014 4:01 PM
  • That sounds like the right behavior. You're canceling the dialog in step 4 so you should get the cancel command rather than the default command.
    Monday, November 17, 2014 4:40 PM
    Owner