ChildWindow.DialogResult Property

Silverlight

Gets or sets a value that indicates whether the ChildWindow was accepted or canceled.

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

'Declaration
<TypeConverterAttribute(GetType(NullableBoolConverter))> _
Public Property DialogResult As Nullable(Of Boolean)

Property Value

Type: System.Nullable(Of Boolean)
true if the child window was accepted; false if the child window was canceled. The default is Nothing.

A ChildWindow is typically used as a dialog box and provides a DialogResult value. DialogResult can be used from the code that showed the ChildWindow to determine whether a user accepted (true) or canceled (false) the dialog box. If a dialog box was accepted, this signifies to the code that opened the child window to retrieve the data that was collected from the user and process it. If a dialog box was canceled, this signifies that the calling code should not process data from the child window.

Setting the DialogResult value automatically closes the child window. Closing the child window in any other way, including calling the Close method, pressing CTRL+SHIFT+F4, or clicking the close button, will set DialogResult to false. DialogResult is Nothing as long as the child window is open.

To get the DialogResult value from a child window, handle the Closed event in the code-behind page of the calling window. In the Closed event handler, cast the sender parameter to a ChildWindow or a derived class to access the DialogResult property.

The following code example demonstrates how to set the DialogResult value in the click events of the OK and Cancel buttons of a ChildWindow. This example is part of a larger example available in the ChildWindow class overview.


Private Sub OKButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles OKButton.Click
    Me.DialogResult = True
End Sub

Private Sub CancelButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs) Handles CancelButton.Click
    Me.DialogResult = False
End Sub


The following example demonstrates how to get the DialogResult value in the Closed event handler. This code is in the page that called the ChildWindow. This example is part of a larger example available in the ChildWindow class overview.


Private Sub loginWnd_Closed(ByVal sender As System.Object, ByVal e As EventArgs)
    Dim lw As LoginWindow = CType(sender, LoginWindow)

    If lw.DialogResult = True AndAlso lw.nameBox.Text <> String.Empty Then
        Me.helloTxt.Text = "Hello " + lw.nameBox.Text
    ElseIf (lw.DialogResult = False) Then
        Me.helloTxt.Text = "Login canceled."
    End If
End Sub


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: