Window.DialogResult 속성

정의

ShowDialog() 메서드에서 반환된 값인 대화 상자 결과 값을 가져오거나 설정합니다.

public:
 property Nullable<bool> DialogResult { Nullable<bool> get(); void set(Nullable<bool> value); };
[System.ComponentModel.TypeConverter(typeof(System.Windows.DialogResultConverter))]
public bool? DialogResult { get; set; }
[<System.ComponentModel.TypeConverter(typeof(System.Windows.DialogResultConverter))>]
member this.DialogResult : Nullable<bool> with get, set
Public Property DialogResult As Nullable(Of Boolean)

속성 값

Nullable<T> 형식의 Boolean 값입니다. 기본값은 false입니다.

특성

예외

DialogResultShowDialog()를 호출하여 창이 열리기 전에 설정됩니다.

또는

DialogResultShow()를 호출하여 창이 열릴 때 설정됩니다.

예제

다음 예제에서는 적절한 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()
        {
            InitializeComponent();
        }

        // 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;
        }
    }
}

Imports System.Windows
Imports System.Windows.Controls

Namespace VisualBasic
    Partial Public Class DialogBox
        Inherits Window
        Public Sub New()
            InitializeComponent()
        End Sub

        ' 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.
        Private Sub acceptButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
            ' Accept the dialog and return the dialog result
            Me.DialogResult = True
        End Sub
    End Class
End Namespace

설명

DialogResult는 대화 상자를 보여 주는 코드에서 사용자가 대화 상자를 수락() 또는 취소(truefalse)했는지 여부를 결정하는 데 사용할 수 있습니다. 대화 상자가 수락된 경우 이는 사용자가 수집한 데이터를 검색하고 처리하는 대화 상자를 연 코드를 의미합니다. 그러나 대화 상자가 취소된 경우 이는 코드 호출이 추가 처리를 중지해야 함을 의미합니다.

기본적으로 사용자가 다음 중 하나를 수행하면 대화 상자가 취소됩니다.

  • PressesALT+F4.

  • 닫기 단추를 클릭합니다.

  • 시스템 메뉴에서 닫기를 선택합니다.

이러한 모든 경우에 는 DialogResult 기본적으로 입니다 false .

대화 상자는 일반적으로 속성을 로 설정한 단추인 대화 상자를 취소하는 true특수 단추를 IsCancel 제공합니다. 이러한 방식으로 구성된 단추는 창을 누르면 창이 닫히거나 ESC 키를 누를 때 자동으로 닫힙니다. 이러한 경우 중 하나에서 은 DialogResult 으로 유지됩니다 false.

대화 상자는 일반적으로 속성이 로 설정된 true단추인 수락 단추를 IsDefault 제공합니다. 이러한 방식으로 구성된 단추는 이벤트를 발생시키거나 ENTER 키를 누르면 이벤트가 발생 Click 합니다. 그러나 대화 상자는 자동으로 닫히지 않으며 로 설정 DialogResulttrue되지도 않습니다. 일반적으로 기본 단추에 대한 이벤트 처리기에서 Click 이 코드를 수동으로 작성해야 합니다.

DialogResultnull 대화 상자가 표시되지만 수락되거나 취소되지 않은 경우 입니다.

대화 상자가 닫히면 메서드에서 반환된 ShowDialog 값이나 속성을 검사하여 DialogResult 대화 결과를 가져올 수 있습니다.

DialogResult 는 메서드를 Window 호출 ShowDialog 하여 를 열 때만 설정할 수 있습니다.

참고

창이 브라우저에서 호스트되는 경우 이 속성을 설정하거나 가져올 수 없습니다.

적용 대상