Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# DialogBox and DialogResult

I want to get the button of the DialogBox that the user clicked ... yet when I use the DialogResult I get this error

'System.Windows.Window.DialogResult' is a 'property' but is used like a 'type'

How can I use the DialogResult??

Ok, I`ve managed to solve it.

MessageBoxResult Result = MessageBox.Show("Message Body", @"Caption/Title", MessageBoxButton.YesNo);
        switch (Result)
        {
            case MessageBoxResult.Yes:
                MessageBox.Show("Yes Pressed!!");
                break;
            case MessageBoxResult.No:
                MessageBox.Show("No Pressed!!");
                break;
        }
like image 728
sikas Avatar asked Oct 14 '22 03:10

sikas


1 Answers

Update: Just realised you're using WPF, not WinForms. Here's a correct implementation of DialogResult within WPF:

MyDialog dialog = new MyDialog();
bool? dialogResult = dialog.ShowDialog();
if (dialogResult.HasValue && dialogResult.Value)
{
   // User clicked OK
}
else
{
   // User clicked Cancel"
}

There's a good tutorial on it here.

Just sounds like you're using the Form's DialogResult property incorrectly. You should be doing something like the following:

DialogResult result = Form.DialogResult;
if (result == DialogResult.Yes)
{
   // Do something
}

You can find the full DialogResult enumeration breakdown here.

like image 96
djdd87 Avatar answered Oct 31 '22 20:10

djdd87