From b0a07ab004f34b9401a20a114a19aa50d119e761 Mon Sep 17 00:00:00 2001 From: Jerome Laban Date: Fri, 23 Apr 2021 10:20:57 -0400 Subject: [PATCH] fix: Add ContentDialog support for WinUI 3 and XamlRoot --- e2e/Uno/HelloUnoWorld.Shared/App.xaml.cs | 12 +++++++++--- .../Dialogs/CustomContentDialog.xaml.cs | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/e2e/Uno/HelloUnoWorld.Shared/App.xaml.cs b/e2e/Uno/HelloUnoWorld.Shared/App.xaml.cs index cd9fa2ba34..0129ddb2a5 100644 --- a/e2e/Uno/HelloUnoWorld.Shared/App.xaml.cs +++ b/e2e/Uno/HelloUnoWorld.Shared/App.xaml.cs @@ -38,6 +38,10 @@ namespace HelloUnoWorld /// sealed partial class App : PrismApplication { + private static Window _window; + + public static XamlRoot MainXamlRoot { get; private set; } + /// /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). @@ -136,11 +140,13 @@ protected override UIElement CreateShell() var shell = Container.Resolve(); #if NET5_0 && WINDOWS - var window = new Window(); - window.Activate(); - window.Content = shell; + _window = new Window(); + _window.Activate(); + _window.Content = shell; #endif + MainXamlRoot = shell.XamlRoot; + return shell; } diff --git a/e2e/Uno/HelloUnoWorld.Shared/Dialogs/CustomContentDialog.xaml.cs b/e2e/Uno/HelloUnoWorld.Shared/Dialogs/CustomContentDialog.xaml.cs index 5287f15593..2a42aeff93 100644 --- a/e2e/Uno/HelloUnoWorld.Shared/Dialogs/CustomContentDialog.xaml.cs +++ b/e2e/Uno/HelloUnoWorld.Shared/Dialogs/CustomContentDialog.xaml.cs @@ -20,6 +20,10 @@ public partial class CustomContentDialog : ContentDialog, IDialogWindow public CustomContentDialog() { InitializeComponent(); + + // This is needed to enable dialog to be created properly. + // See: https://github.com/microsoft/microsoft-ui-xaml/issues/4251 + XamlRoot = App.MainXamlRoot; } public IDialogResult Result { get ; set; }