Click here to Skip to main content
11,479,412 members (37,178 online)
Click here to Skip to main content

Tagged as

TIP: Handling WPF DialogResult with simplicity

, 4 Sep 2010 CPOL 21.7K 1
Rate this:
Please Sign up or sign in to vote.
Shorter way to evaluate DialogResult after calling Window.ShowDialog
I have seen many code snippets like:
if (frm.DialogResult.HasValue && frm.DialogResult.Value) 
   // do something here
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:
if (frm.DialogResult.Equals(true))
   // do something here


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


About the Author

Jaime Olivares
Architect Freelance (
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 C# 2013 and TFS.
Follow on   LinkedIn

Comments and Discussions

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

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 4 Sep 2010
Article Copyright 2010 by Jaime Olivares
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid