Question

I am working with Modern UI and attempting to make a dialog box that asks a question and then waits for a response. I can do this with messagebox but though I would try using modern UI. I am unsure of how to get the button clicked value.

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");
    }
}
Was it helpful?

Solution 2

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

OTHER TIPS

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

It might be another solution using extension method.

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;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top