internal DialogButtonViewModel(DialogButtons button, MessageDialogViewModel dlvm)
 {
     Caption = button.ToString();
     Command = new SimpleCommand()
     {
         ExecuteDelegate =
             (obj) =>
         {
             dlvm.SelectedButton = button;
         }
     };
 }
        async public Task <DialogResult> ShowAsync(string message, string title, DialogButtons buttons)
        {
            if (string.IsNullOrEmpty(message))
            {
                throw new ArgumentException(
                          "The specified message cannot be null or empty.", "message");
            }
            if (string.IsNullOrEmpty(title))
            {
                throw new ArgumentException(
                          "The specified title cannot be null or empty.", "title");
            }

            MessageDialog dialog = new MessageDialog(message, title);
            DialogResult  result = DialogResult.None;

            switch (buttons)
            {
            case DialogButtons.OK:
            {
                dialog.Commands.Add(
                    new UICommand("OK", new UICommandInvokedHandler(
                                      o => result = DialogResult.OK)));
                break;
            }

            case DialogButtons.OKCancel:
            {
                dialog.Commands.Add(new UICommand("OK",
                                                  new UICommandInvokedHandler(o => result = DialogResult.OK)));
                dialog.Commands.Add(new UICommand("Cancel",
                                                  new UICommandInvokedHandler(o => result = DialogResult.Cancel)));
                break;
            }

            case DialogButtons.YesNo:
            {
                dialog.Commands.Add(new UICommand("Yes",
                                                  new UICommandInvokedHandler(o => result = DialogResult.Yes)));
                dialog.Commands.Add(new UICommand("No",
                                                  new UICommandInvokedHandler(o => result = DialogResult.No)));
                break;
            }

            default:
            {
                throw new NotSupportedException(
                          string.Format("DialogButtons.{0} is not supported.",
                                        buttons.ToString()));
            }
            }
            dialog.DefaultCommandIndex = 1;
            // Determine whether the calling thread is the
            // thread associated with the Dispatcher.
            if (Window.Current.Dispatcher.HasThreadAccess)
            {
                await dialog.ShowAsync();
            }
            else
            {
                // Execute asynchronously on the thread the Dispatcher is associated with.
                await Window.Current.Dispatcher.RunAsync(
                    CoreDispatcherPriority.Normal, async() =>
                {
                    await dialog.ShowAsync();
                });
            }
            return(result);
        }