Click here to Skip to main content
15,880,905 members
Articles / Desktop Programming / WPF
Tip/Trick

TIP: Handling WPF DialogResult with simplicity

Rate me:
Please Sign up or sign in to vote.
3.89/5 (8 votes)
4 Sep 2010CPOL 37.2K   1   2
Shorter way to evaluate DialogResult after calling Window.ShowDialog
I have seen many code snippets like:
 
C#
frm.ShowDialog();
if (frm.DialogResult.HasValue && frm.DialogResult.Value) 
{
   // do something here
}
or
C#
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:
C#
frm.ShowDialog();
if (frm.DialogResult.Equals(true))
{
   // do something here
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
Peru Peru


Computer Electronics professional, Software Architect and senior Windows C++ and C# developer with experience in many other programming languages, platforms and application areas including communications, simulation systems, PACS/DICOM (radiology), GIS, 3D graphics and HTML5-based web applications.
Currently intensively working with Visual Studio and TFS.

Comments and Discussions

 
QuestionMy 2 cents Pin
Thomas Polaert14-Dec-12 0:49
Thomas Polaert14-Dec-12 0:49 
GeneralThanks.. I guess the best way to check for bool? is the make... Pin
Simon Dufour19-Aug-10 3:24
Simon Dufour19-Aug-10 3:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.