Skip to content

Commit

Permalink
fix: Add ContentDialog support for WinUI 3 and XamlRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 23, 2021
1 parent 1977544 commit b0a07ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions e2e/Uno/HelloUnoWorld.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ namespace HelloUnoWorld
/// </summary>
sealed partial class App : PrismApplication
{
private static Window _window;

public static XamlRoot MainXamlRoot { get; private set; }

/// <summary>
/// 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().
Expand Down Expand Up @@ -136,11 +140,13 @@ protected override UIElement CreateShell()
var shell = Container.Resolve<Shell>();

#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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down

0 comments on commit b0a07ab

Please sign in to comment.