Current issues with the user interface dialog

I work with Modern UI and try to make a dialog box that asks a question and then waits for an answer. I can do this with a message, but although I would try to use a modern interface. I am not sure how to get the value clicked on the button.

if (testapp.linkvalue != "NULL")
{
    var v = new ModernDialog
    {
        Title = "my test",
        Content = "pewpew lazers rule. If you agree click ok"
    };
    v.Buttons = new Button[] { v.OkButton, v.CancelButton };
    var r = v.ShowDialog();
    if (????????????????)
    {
        MessageBox.Show("ok was clicked");
    }
    else
    {
        MessageBox.Show("cancel was clicked");
    }
}
+3
source share
3 answers
private void CommonDialog_Click(object sender, RoutedEventArgs e)
    {
        var dlg = new ModernDialog {
            Title = "Common dialog",
            Content = new LoremIpsum()
        };
        dlg.Buttons = new Button[] { dlg.OkButton, dlg.CancelButton};
        dlg.ShowDialog();

        this.dialogResult.Text = dlg.DialogResult.HasValue ? dlg.DialogResult.ToString() : "<null>";
        this.dialogMessageBoxResult.Text = dlg.MessageBoxResult.ToString();
    }
+2
source
if (testapp.linkvalue != "NULL")
{
    var v = new ModernDialog
    {
        Title = "my test",
        Content = "pewpew lazers rule. If you agree click ok"
    };
v.OkButton.Click += new RoutedEventHandler(OkButton_Click);
    v.Buttons = new Button[] { v.OkButton, v.CancelButton };
    var r = v.ShowDialog();

}

//And Then Create OkButtonClick

private void OkButton_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("ok was clicked");
        }
+5
source

.

var r = v.ShowDialogOKCancel();
if (r==MessageBoxResult.OK)
{
    MessageBox.Show("ok was clicked");
}
else
{
    MessageBox.Show("cancel was clicked");
}



static class ModernDialogExtension
{
    static MessageBoxResult result;

    public static MessageBoxResult ShowDialogOKCancel(this FirstFloor.ModernUI.Windows.Controls.ModernDialog modernDialog)
    {
        result = MessageBoxResult.Cancel;

        modernDialog.OkButton.Click += new RoutedEventHandler(OkButton_Click);
        modernDialog.Buttons = new Button[] { modernDialog.OkButton, modernDialog.CloseButton };

        modernDialog.ShowDialog();

        return result;
    }

    private static void OkButton_Click(object sender, RoutedEventArgs e)
    {
        result = MessageBoxResult.OK;
    }
}
+2

All Articles