This documentation is archived and is not being maintained.

Window.DialogResult Property

Updated: October 2009

Gets or sets the dialog result value, which is the value that is returned from the ShowDialog method.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)

public function get DialogResult () : Nullable<boolean>
public function set DialogResult (value : Nullable<boolean>)
You cannot set this property in XAML.

Property Value

Type: System.Nullable(Boolean)
A Nullable(T) value of type Boolean. The default is false.


DialogResult is set before a window is opened by calling ShowDialog, or a window opened by calling Show.

When a Window is opened by calling its ShowDialog method, the DialogResult property can be used to determine whether the user accepted (true) or canceled (false) the dialog box.

By default, a dialog box is canceled when a user performs one of the following actions:

  • Presses ALT+F4.

  • Clicks the Close button.

  • Selects Close from the System menu.

In all of these cases, DialogResult is false by default.

A dialog box typically provides a special button to cancel a dialog box, which is the button whose IsCancel property is set to true. A button configured this way will automatically close the dialog box when either it is clicked, or when the ESC key is pressed. In either of these cases, DialogResult remains false.

A dialog box also typically provides an accept button, which is the button whose IsDefault property is set to true. A button configured this way will raise its Click event when either it is clicked or the ENTER key is pressed. However, it will not automatically close the dialog box, nor will it set DialogResult to true. You need to manually write this code, usually from the Click event handler for the accept button. Note that DialogResult can only be set when a Window is opened by calling its ShowDialog method.

DialogResult is a null reference (Nothing in Visual Basic) when the dialog box is shown but neither accepted nor canceled.

After a dialog box is closed, you can get the dialog box result from the value returned by ShowDialog method, or by inspecting the DialogResult property.


You cannot set or get this property when a window is hosted in a browser.

The following example shows how to configure an OK button and a Cancel button to return the appropriate DialogResult.

<Button IsDefault="True" Click="acceptButton_Click">OK (IsDefault=True)</Button>
<Button IsCancel="True">Cancel (IsCancel=True)</Button>
using System;
using System.Windows;
using System.Windows.Controls;

namespace CSharp
    public partial class DialogBox : Window
        public DialogBox()

        // The accept button is a button whose IsDefault property is set to true. 
        // This event is raised whenever this button is clicked, or the ENTER key 
        // is pressed. 
        void acceptButton_Click(object sender, RoutedEventArgs e)
            // Accept the dialog and return the dialog result 
            this.DialogResult = true;

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0




October 2009

Clarified use of DialogResult with ShowDialog.

Customer feedback.

February 2009

Added information about the null case.

Customer feedback.