Search code examples
c#modern-ui

Modern UI Dialog result issues


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

Solution

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