【问题标题】:C++/winRT xaml ContentDialog exampleC++/winRT xaml ContentDialog 示例
【发布时间】:2020-09-02 18:32:41
【问题描述】:

文档显示了这个 C# sn-p:

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

我要求的是这个 sn-p 的 C++/winRT 版本。

【问题讨论】:

    标签: c++-winrt


    【解决方案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)
        {
    
        }
    }
    

    【讨论】:

      【解决方案2】:

      我想在单击按钮时打开内容对话框,所以我尝试了Kenny Kerr 提供的代码 sn-p。一切似乎都正常工作,没有错误,但是当我单击按钮时,没有看到任何对话框。我通过放置下面的代码来修复它

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

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

      【讨论】:

        猜你喜欢
        • 2022-12-09
        • 1970-01-01
        • 2020-12-22
        • 1970-01-01
        • 1970-01-01
        • 2013-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多