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

Alex Baranosky picture Alex Baranosky · Feb 3, 2009 · Viewed 51.4k times · Source

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.

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

Answer

JMD picture JMD · Feb 3, 2009

http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx

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.