C ++ / winRT xaml ContentDialog示例

时间:2019-01-16 02:38:47

标签: 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.
        }
    }

我要的是此代码段的C ++ / winRT版本。

2 个答案:

答案 0 :(得分:1)

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)
    {

    }
}

答案 1 :(得分:0)

我想在单击按钮时打开内容对话框,所以我尝试了Kenny Kerr提供的代码段。一切似乎都正常运行,没有错误,但是当我单击按钮时,没有看到对话框。我通过将其放置在代码下方来修复它

 dialog.XamlRoot(myButton().XamlRoot());
   

auto result = co_await dialog.ShowAsync()行之前。