--- lang: ja-jp breaks: true --- # WinUI 3 ContentDialog から ContentDialog を開くことは出来ない 2022-11-24 > AppWindow 内または XAML Islands 内の ContentDialog > https://learn.microsoft.com/ja-jp/windows/apps/design/controls/dialogs-and-flyouts/dialogs#contentdialog-in-appwindow-or-xaml-islands :::warning 1 つのスレッドで一度に開くことのできる ContentDialog は 1 つだけです。 2 つの ContentDialog を開こうとすると、個別の AppWindow で開く場合でも、例外がスローされます。 以下の例外が発生する。 ```= System.Runtime.InteropServices.COMException: 'An async operation was not properly started. (0x80000019)' ``` ::: :::info この仕様は、UWPも同じ。 ::: ## DialogPage.xaml ```xml= <Page x:Class="App4_DisplayingDialogsFromDialog.DialogPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:App4_DisplayingDialogsFromDialog" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid> <StackPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch"> <!-- Content body --> <TextBlock Text="Lorem ipsum dolor sit amet, adipisicing elit." TextWrapping="Wrap" /> <CheckBox Content="Upload your content to the cloud."/> </StackPanel> </Grid> </Page> ``` ## MainWindow.xaml.cs ```csharp= public sealed partial class MainWindow : Window { public MainWindow() { this.InitializeComponent(); } private async Task ShowContentDialog() { ContentDialog dialog = new ContentDialog(); dialog.Title = "Save your work?"; dialog.PrimaryButtonText = "Save"; dialog.SecondaryButtonText = "Don't Save"; dialog.CloseButtonText = "Cancel"; dialog.DefaultButton = ContentDialogButton.Primary; dialog.Content = new DialogPage(); dialog.XamlRoot = this.Content.XamlRoot; dialog.PrimaryButtonClick += Dialog_PrimaryButtonClick; var result = await dialog.ShowAsync(); } private async void myButton_Click(object sender, RoutedEventArgs e) { myButton.Content = "Clicked"; await ShowContentDialog(); } private async void Dialog_PrimaryButtonClick( ContentDialog sender, ContentDialogButtonClickEventArgs args ) { ContentDialog contentDialog = new ContentDialog { Title = "ダイアログタイトル", Content = "コンテンツ(メッセージ内容)", CloseButtonText = "ボタンに表示するテキスト" }; contentDialog.XamlRoot = this.Content.XamlRoot; ContentDialogResult result = await contentDialog.ShowAsync(); } } ``` ###### tags: `WinUI 3` `ContentDialog`