Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DialogResult in WPF Application

Tags:

c#

wpf

I am currently developing an application in C# using WPF, I have always only used WinForms. Normally if I want to ask the user a question instead of making my own dialogue I use

DialogResult result = MessageBox.Show(
    "My Message Question", "My Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

This is the first time that I have used a WPF form and DialogResult does not seem to be available. What do I use to get the same effect?

like image 833
Boardy Avatar asked Nov 30 '10 20:11

Boardy


People also ask

What is DialogResult WPF?

DialogResult is set before a window is opened by calling ShowDialog(). -or- DialogResult is set on a window that is opened by calling Show().

What is DialogResult c#?

DialogResult is returned by dialogs after dismissal. It indicates which button was clicked on the dialog by the user. It is used with the MessageBox.

What is dialog box in WPF?

Common dialog boxes As a user uses a common dialog box in one application, they don't need to learn how to use that dialog box in other applications. WPF encapsulates the open file, save file, and print common dialog boxes and exposes them as managed classes for you to use in standalone applications.

How do I close a WPF window?

window. ShowDialog(); Close method of the Window class is used to close a window.


2 Answers

Here is how you do the same in WPF:

MessageBoxResult result = MessageBox.Show("My Message Question", "My Title", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
    // Do this
}
like image 108
Lane Avatar answered Nov 13 '22 15:11

Lane


Use MessageBoxResult instead. And use the MessageBox class. But this message box will look pretty ugly "classic" style.

Another option would be to use Extended WPF toolkit

Yet another option would be to go here and download CrossTechnologySamples.exe then look into the VistaBridge project. I recommend you give a good look here because you will find other samples for other dialogs (like FileOpen, FileSave etc.) that do not exist by default in WPF.

like image 30
Liviu Mandras Avatar answered Nov 13 '22 16:11

Liviu Mandras