MessageDialog 클래스

정의

사용자에게 메시지를 표시하기 위한 대화 상자를 나타냅니다.

데스크톱 앱에서 UI를 표시하는 방식으로 이 클래스의 instance 사용하기 전에 개체를 소유자의 창 핸들과 연결해야 합니다. 자세한 정보 및 코드 예제는 CoreWindow에 의존하는 WinRT UI 개체 표시를 참조하세요.

중요

MessageDialog를 사용하는 유니버설 Windows 8.x 앱을 업그레이드하고 변경 내용을 최소화해야 하거나 앱이 XAML이 아닌 경우에만 MessageDialog를 사용해야 합니다. Windows 10+의 새 XAML 앱의 경우 ContentDialog 컨트롤을 대신 사용하는 것이 좋습니다.

public ref class MessageDialog sealed
/// [Windows.Foundation.Metadata.Activatable(Windows.UI.Popups.IMessageDialogFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
class MessageDialog final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
/// [Windows.Foundation.Metadata.Activatable(Windows.UI.Popups.IMessageDialogFactory, 65536, "Windows.Foundation.UniversalApiContract")]
class MessageDialog final
[Windows.Foundation.Metadata.Activatable(typeof(Windows.UI.Popups.IMessageDialogFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
public sealed class MessageDialog
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Standard)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.UI.Popups.IMessageDialogFactory), 65536, "Windows.Foundation.UniversalApiContract")]
public sealed class MessageDialog
function MessageDialog(content, title)
Public NotInheritable Class MessageDialog
상속
Object Platform::Object IInspectable MessageDialog
특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

다음 예제에서는 메시지 대화 상자에 명령을 추가하고 표시하는 방법을 보여 줍니다. 전체 코드 예제는 메시지 대화 상자 샘플을 참조하세요.

using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;
using SDKTemplate;
using System;

private async void CancelCommandButton_Click(object sender, RoutedEventArgs e)
{
    // Create the message dialog and set its content
    var messageDialog = new MessageDialog("No internet connection has been found.");

    // Add commands and set their callbacks; both buttons use the same callback function instead of inline event handlers
    messageDialog.Commands.Add(new UICommand(
        "Try again", 
        new UICommandInvokedHandler(this.CommandInvokedHandler)));
    messageDialog.Commands.Add(new UICommand(
        "Close", 
        new UICommandInvokedHandler(this.CommandInvokedHandler)));

    // Set the command that will be invoked by default
    messageDialog.DefaultCommandIndex = 0;

    // Set the command to be invoked when escape is pressed
    messageDialog.CancelCommandIndex = 1;

    // Show the message dialog
    await messageDialog.ShowAsync();
}

private void CommandInvokedHandler(IUICommand command)
{
    // Display message showing the label of the command that was invoked
    rootPage.NotifyUser("The '" + command.Label + "' command has been selected.", 
        NotifyType.StatusMessage);
}
// MainPage.cpp
#include "pch.h"
#include "MainPage.h"

#include <winrt/Windows.UI.Popups.h>

#include "winrt/Windows.System.h"
#include "winrt/Windows.UI.Xaml.Controls.h"
#include "winrt/Windows.UI.Xaml.Input.h"
#include "winrt/Windows.UI.Xaml.Navigation.h"
#include <sstream>

using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::UI::Xaml;
...
void MainPage::CancelCommandButton_Click(IInspectable const&, RoutedEventArgs const&)
{
    // Create the message dialog and set its content
    Windows::UI::Popups::MessageDialog msg{ L"No internet connection has been found." };

    // Add commands and set their callbacks.
    // Both commands use the same callback function instead of inline event handlers.
    Windows::UI::Popups::UICommand continueCommand{
        L"Try again",
        { this, &MainPage::CommandInvokedHandler} };
    Windows::UI::Popups::UICommand upgradeCommand{
        L"Close",
        { this, &MainPage::CommandInvokedHandler } };

    // Add the commands to the dialog.
    msg.Commands().Append(continueCommand);
    msg.Commands().Append(upgradeCommand);

    // Set the command that will be invoked by default.
    msg.DefaultCommandIndex(0);

    // Set the command to be invoked when escape is pressed.
    msg.CancelCommandIndex(1);

    // Show the message dialog.
    msg.ShowAsync();
}

void MainPage::CommandInvokedHandler(Windows::UI::Popups::IUICommand const& command)
{
    // Display message.
    std::wstringstream stringstream;
    stringstream << L"The '" << command.Label().c_str() << L"' command has been selected.";
    rootPage.NotifyUser(stringstream.str().c_str(), NotifyType::StatusMessage);
}
#include "pch.h"
#include "CancelCommand.xaml.h"

using namespace MessageDialogSample;

using namespace Windows::UI::Popups;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Navigation;

void MessageDialogSample::CancelCommand::CancelCommandButton_Click(Platform::Object^ sender,
    Windows::UI::Xaml::RoutedEventArgs^ e)
{
    // Create the message dialog and set its content
    MessageDialog^ msg = ref new MessageDialog("No internet connection has been found.");

    // Add commands and set their callbacks.
    // Both commands use the same callback function instead of inline event handlers.
    UICommand^ continueCommand = ref new UICommand(
        "Try again", 
        ref new UICommandInvokedHandler(this, &CancelCommand::CommandInvokedHandler));
    UICommand^ upgradeCommand = ref new UICommand(
        "Close", 
        ref new UICommandInvokedHandler(this, &CancelCommand::CommandInvokedHandler));

    // Add the commands to the dialog
    msg->Commands->Append(continueCommand);
    msg->Commands->Append(upgradeCommand);

    // Set the command that will be invoked by default
    msg->DefaultCommandIndex = 0;

    // Set the command to be invoked when escape is pressed
    msg->CancelCommandIndex = 1;

    // Show the message dialog
    msg->ShowAsync();
}

void CancelCommand::CommandInvokedHandler(Windows::UI::Popups::IUICommand^ command)
{
    // Display message
    rootPage->NotifyUser("The '" + command->Label + "' command has been selected.", 
        NotifyType::StatusMessage);
}
Imports Windows.UI.Popups
Imports Windows.UI.Xaml
Imports Windows.UI.Xaml.Controls
Imports Windows.UI.Xaml.Navigation
Imports SDKTemplate

Partial Public NotInheritable Class CloseCommand
    Inherits SDKTemplate.Common.LayoutAwarePage

    ' A pointer back to the main page.  This is needed if you want to call methods in MainPage such
    ' as NotifyUser()
    Private rootPage As MainPage = MainPage.Current

    Public Sub New()
        Me.InitializeComponent()
    End Sub

    Private Async Sub CloseCommandLaunch_Click(sender As Object, e As RoutedEventArgs)
        ' Create the message dialog and set its content and title
        Dim messageDialog = New MessageDialog("No internet connection has been found.")

        ' Add buttons and set their callbacks
        messageDialog.Commands.Add(New UICommand("Try again", Sub(command)
            rootPage.NotifyUser("The '" & command.Label & "' button has been selected.", _ 
                NotifyType.StatusMessage)
                                                              End Sub))

        messageDialog.Commands.Add(New UICommand("Close", Sub(command) 
            rootPage.NotifyUser("The '" & command.Label & "' button has been selected.", _
                NotifyType.StatusMessage)
                                                          End Sub))

        ' Set the command that will be invoked by default
        messageDialog.DefaultCommandIndex = 0

        ' Set the command to be invoked when escape is pressed
        messageDialog.CancelCommandIndex = 1

        ' Show the message dialog
        Await messageDialog.ShowAsync
    End Sub
End Class

설명

참고

이 클래스는 민첩하지 않으므로 스레딩 모델 및 마샬링 동작을 고려해야 합니다. 자세한 내용은 스레딩 및 마샬링(C++/CX)다중 스레드 환경(.NET)에서 Windows 런타임 개체 사용을 참조하세요.

대화 상자에는 데스크톱 앱에서 최대 3개의 명령 또는 모바일 앱에서 두 개의 명령을 지원할 수 있는 명령 모음이 있습니다. 명령을 지정하지 않으면 기본 명령이 추가되어 대화 상자를 닫습니다. 대화 상자는 화면 뒤의 화면을 흐리게 하고 사용자가 응답할 때까지 터치 이벤트가 앱의 캔버스로 전달되지 않도록 차단합니다.

메시지 대화 상자는 드물게 사용해야 하며 사용자의 흐름을 차단해야 하는 중요한 메시지 또는 간단한 질문에만 사용해야 합니다. 다음은 예제 섹션의 코드에서 만든 대화 상자의 예 입니다 .

두 명령이 있는 메시지 대화 상자

생성자

MessageDialog(String)

MessageDialog 클래스의 새 instance 초기화하여 사용자에게 간단한 질문을 하는 데 사용할 수 있는 제목 없는 메시지 대화 상자를 표시합니다.

데스크톱 앱에서 UI를 표시하는 방식으로 이 클래스의 instance 사용하기 전에 개체를 소유자의 창 핸들과 연결해야 합니다. 자세한 정보 및 코드 예제는 CoreWindow에 의존하는 WinRT UI 개체 표시를 참조하세요.

대화 상자는 화면 뒤의 화면을 흐리게 하고 사용자가 응답할 때까지 터치 이벤트가 앱의 캔버스로 전달되지 않도록 차단합니다.

메시지 대화 상자는 드물게 사용해야 하며 사용자의 흐름을 차단해야 하는 중요한 메시지 또는 간단한 질문에만 사용해야 합니다.

MessageDialog(String, String)

MessageDialog 클래스의 새 instance 초기화하여 사용자에게 간단한 질문을 하는 데 사용할 수 있는 메시지 대화 상자를 표시합니다.

데스크톱 앱에서 UI를 표시하는 방식으로 이 클래스의 instance 사용하기 전에 개체를 소유자의 창 핸들과 연결해야 합니다. 자세한 정보 및 코드 예제는 CoreWindow에 의존하는 WinRT UI 개체 표시를 참조하세요.

속성

CancelCommandIndex

취소 명령으로 사용할 명령의 인덱스 를 가져오거나 설정합니다. 사용자가 ESC 키를 누를 때 발생하는 명령입니다.

인덱스를 설정하기 전에 명령을 추가합니다.

Commands

메시지 대화 상자의 명령 모음에 표시되는 명령 배열을 가져옵니다. 이러한 명령은 대화 상자를 실행 가능하게 만듭니다.

이 배열을 가져와서 명령을 나타내는 UICommand 개체를 추가합니다. 대화 상자가 현재 표시되면 명령 모음에 명령이 추가되지 않습니다.

Content

사용자에게 표시할 메시지를 가져오거나 설정합니다.

DefaultCommandIndex

기본값으로 사용할 명령의 인덱스 를 가져오거나 설정합니다. 사용자가 ENTER 키를 누를 때 기본적으로 실행되는 명령입니다.

인덱스를 설정하기 전에 명령을 추가합니다.

Options

MessageDialog에 대한 옵션을 가져오거나 설정합니다.

Title

대화 상자에 표시할 제목(있는 경우)을 가져오거나 설정합니다.

메서드

ShowAsync()

대화 상자를 표시하는 비동기 작업을 시작합니다.

적용 대상

추가 정보