views:

89

answers:

5

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;
        }
+3  A: 
GenericTypeTea
This is actually incorrect. He's using WPF's (or Silverlight's) DialogResult property - this is for Windows Forms. See the full name of the error message.
Reed Copsey
@Reed- thanks for pointing it out, I'll update!
GenericTypeTea
it didn`t work ... the type or namespace 'MyDialog' could not be found
sikas
MyDialog is just an example. You have to replace MyDialog with your Dialog/Class name.
GenericTypeTea
I have found a solution and added it to my question.
sikas
@Sikas - maybe next time you'll tell us that you're using a MessageBox and show some example code of what you were trying to do.
GenericTypeTea
A: 

DialogResult is Enum - you can directly compare with the DialogResult Property of your form.

Tumbleweed
A: 

Do you need a DialogBox? Or would a MessageBox work for your purposes?

 DialogResult dlg = MessageBox.Show("Question User?",
                   "MessageBox Title",
                   MessageBoxButtons.YesNo,
                   MessageBoxIcon.Question);
            if (dlg == DialogResult.No)
            {
                //user changed mind. return
                return;
            }

etc.

Raven Dreamer
DialogBox doesn`t work Raven, it is not found!!
sikas
I want a MessageBox to act upon user click, if the user clicks yes option1 performed, if no then option2 performed.
sikas
I have found a solution and added it to my question. Thanks.
sikas
Glad I could help. Don't forget to select the answer that helped you get there.
Raven Dreamer
A: 

If you are using WPF or Silverlight then DialogResult is a bool? and you can use ?? to supply a value if the result is null.

if (myWindow.DialogResult ?? false)
    Debug.WriteLine("You clicked OK");
else
    Debug.WriteLine("You clicked Cancel");
Doug Ferguson
I have found a solution and added it to my question. Thanks.
sikas
A: 

You're using WPF's DialogResult property, which is a Nullable<bool>, not an enumeration.

You need to check the result like so:

bool? dialogResult = dialogBox.ShowDialog();

if (dialogResult.HasValue) // Should always have a value, at this point, since the dialogBox.ShowDialog() returned at this point.  Will be false until the dialog is closed, however
{
    if (dialogResult.Value)
    {
        // User "accepted" the dialog, hitting yes, OK, etc...
    }
    else
    {
        // User hit "cancel" button
    }
}
Reed Copsey
I have found a solution and added it to my question. Thanks
sikas