diff --git a/samples/ControlGallery/AppShell.razor b/samples/ControlGallery/AppShell.razor
index 208aa846..1b8771db 100644
--- a/samples/ControlGallery/AppShell.razor
+++ b/samples/ControlGallery/AppShell.razor
@@ -13,82 +13,85 @@
@using ControlGallery.Views.Shell
@using ControlGallery.Views.Menus
-
+
+
- @*Present data*@
-
-
-
+ @*Present data*@
+
+
+
- @*Initiate commands*@
-
-
-
-
+ @*Initiate commands*@
+
+
+
+
- @*Set values*@
-
-
-
-
-
-
+ @*Set values*@
+
+
+
+
+
+
- @*Edit text*@
-
-
+ @*Edit text*@
+
+
- @*Display collections*@
-
-
-
-
-
-
-
-
-
-
-
+ @*Display collections*@
+
+
+
+
+
+
+
+
+
+
+
- @*Layouts*@
-
-
-
+ @*Layouts*@
+
+
+
- @*Shell*@
-
-
-
-
-
+ @*Shell*@
+
+
+
+
+
-
+
- @*Navigation*@
-
-
-
-
+ @*Navigation*@
+
+
+
+
- @*Other*@
-
-
-
-
+ @*Other*@
+
+
+
+
- @if (DeviceInfo.Platform == DevicePlatform.WinUI || DeviceInfo.Platform == DevicePlatform.MacCatalyst)
- {
-
-
- }
-
+ @if (DeviceInfo.Platform == DevicePlatform.WinUI || DeviceInfo.Platform == DevicePlatform.MacCatalyst)
+ {
+
+
+
+ }
+
+
@code {
Color _backgroundColor;
diff --git a/samples/ControlGallery/Views/Menus/ContextMenuPage.razor b/samples/ControlGallery/Views/Menus/ContextMenuPage.razor
index 91deecde..fce80df2 100644
--- a/samples/ControlGallery/Views/Menus/ContextMenuPage.razor
+++ b/samples/ControlGallery/Views/Menus/ContextMenuPage.razor
@@ -24,7 +24,7 @@
@code {
- Color? _selectedColor = null;
+ Color _selectedColor = null;
void SelectColor(Color color) => _selectedColor = color;
}
diff --git a/samples/ControlGallery/Views/WindowExample.razor b/samples/ControlGallery/Views/WindowExample.razor
new file mode 100644
index 00000000..d16c898f
--- /dev/null
+++ b/samples/ControlGallery/Views/WindowExample.razor
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/ControlGallery/Views/WindowsPage.razor b/samples/ControlGallery/Views/WindowsPage.razor
new file mode 100644
index 00000000..c6a4141f
--- /dev/null
+++ b/samples/ControlGallery/Views/WindowsPage.razor
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+@code {
+ [Inject] INavigation Navigation { get; set; }
+
+ async Task OpenWindow()
+ {
+ await Navigation.OpenWindow();
+ }
+}
diff --git a/src/BlazorBindings.Maui/BlazorBindingsApplication.cs b/src/BlazorBindings.Maui/BlazorBindingsApplication.cs
index ec4cecc2..97331f53 100644
--- a/src/BlazorBindings.Maui/BlazorBindingsApplication.cs
+++ b/src/BlazorBindings.Maui/BlazorBindingsApplication.cs
@@ -1,4 +1,6 @@
-using Microsoft.Maui.Controls;
+using BlazorBindings.Maui.Elements.Handlers;
+using Microsoft.Maui.Controls;
+using System.Runtime.ExceptionServices;
namespace BlazorBindings.Maui;
@@ -27,12 +29,21 @@ protected override Window CreateWindow(Microsoft.Maui.IActivationState activatio
}
var (componentType, parameters) = GetComponentToRender();
- var window = new Window();
- var task = renderer.AddComponent(componentType, window, parameters);
- AwaitVoid(task);
- return window;
+ var handler = new ApplicationWindowHandler();
+ var addComponentTask = renderer.AddComponent(componentType, handler, parameters);
+
+ if (addComponentTask.Exception != null)
+ {
+ // If exception was thrown during the sync execution - throw it straight away.
+ ExceptionDispatchInfo.Throw(addComponentTask.Exception.InnerException);
+ }
+
+ AwaitVoid(handler.WaitForWindowAsync());
+ return handler.TargetElement;
+
+ // async void is used here to crash the application if rendering fails.
static async void AwaitVoid(Task task) => await task;
}
diff --git a/src/BlazorBindings.Maui/Elements/Handlers/ApplicationWindowHandler.cs b/src/BlazorBindings.Maui/Elements/Handlers/ApplicationWindowHandler.cs
new file mode 100644
index 00000000..89eacc27
--- /dev/null
+++ b/src/BlazorBindings.Maui/Elements/Handlers/ApplicationWindowHandler.cs
@@ -0,0 +1,51 @@
+using BlazorBindings.Maui.Extensions;
+using MC = Microsoft.Maui.Controls;
+
+namespace BlazorBindings.Maui.Elements.Handlers;
+
+// We allow root component to be either a window, or a page. Therefore, this handler supports both.
+internal class ApplicationWindowHandler : IContainerElementHandler
+{
+ private TaskCompletionSource