C++/winRT xaml ContentDialog example
Asked Answered
S

2

5

The documentation shows this C# snippet:

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.
        }
    }

What I'm requesting is a C++/winRT version of this snippet.

Seneca answered 16/1, 2019 at 2:38 Comment(0)
W
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)
    {

    }
}
Ware answered 16/1, 2019 at 17:39 Comment(0)
C
2

I wanted to open content dialog on button click so I tried the code snippet provided by Kenny Kerr. Everything seemed to work fine without error but when i clicked the button no dialog was seen. i fixed it by placing below code

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

Before auto result = co_await dialog.ShowAsync() line.

Chiller answered 2/9, 2020 at 10:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.