C++/winRT xaml ContentDialog 示例

Jac*_*ick 5 c++-winrt

文档显示了这个 C# 片段:

async void DisplayDeleteFileDialog(){
    ContentDialog deleteFileDialog = new ContentDialog{
        Title = "Delete file permanently?",
        Content = "If you delete this file, you won't be able to recover it. Do you want to delete it?",
        PrimaryButtonText = "Delete",
        CloseButtonText = "Cancel"
    };

    ContentDialogResult result = await deleteFileDialog.ShowAsync();

    // Delete the file if the user clicked the primary button.
    /// Otherwise, do nothing.
    if (result == ContentDialogResult.Primary) {
         // Delete the file.
        }
    else {
         // The user clicked the CLoseButton, pressed ESC, Gamepad B, or the system back button.
         // Do nothing.
        }
    }
Run Code Online (Sandbox Code Playgroud)

我请求的是此代码片段的 C++/winRT 版本。

Ken*_*err 7

IAsyncAction Async()
{
    ContentDialog dialog;
    dialog.Title(box_value(L"title"));
    dialog.Content(box_value(L"content"));
    dialog.PrimaryButtonText(L"primary");
    dialog.CloseButtonText(L"close");

    auto result = co_await dialog.ShowAsync();

    if (result == ContentDialogResult::Primary)
    {

    }
}
Run Code Online (Sandbox Code Playgroud)