.net – How to get System.Windows.ShowDialog() to return ‘true’


How do I get System.Windows.ShowDialog() to return 'true'?

I am a little new to this. System.Windows.ShowDialog's return type is bool? It is supposed to return true when you hit Submit, and false when you hit Cancel. But I am not sure how to designate which Button is the official submit button.

On a related note, I am curious as to how it can return null.

Best Solution


ShowDialog returns a Nullable<Boolean> value that specifies whether the activity was accepted or canceled. The return value is the value of the DialogResult property before a window closes (see DialogResult).

Basically, you decide by setting the value of the DialogResult, not by hitting a particular button -- you decide what the button does.