Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

TIP: Handling WPF DialogResult with simplicity

0.00/5 (No votes)
4 Sep 2010 1  
Shorter way to evaluate DialogResult after calling Window.ShowDialog
I have seen many code snippets like:
 
frm.ShowDialog();
if (frm.DialogResult.HasValue && frm.DialogResult.Value) 
{
   // do something here
}
or
DialogResult result = frm.ShowDialog();
if (result.HasValue && result.Value)
{
   // do something here
}
This double check is done because DialogResult is of nullable type: bool?, but evaluation can be as simple as:
frm.ShowDialog();
if (frm.DialogResult.Equals(true))
{
   // do something here
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here