-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
507 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<Window Title="New window"> | ||
<ContentPage> | ||
<VerticalStackLayout> | ||
<Label>Newly opened window.</Label> | ||
</VerticalStackLayout> | ||
</ContentPage> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<ContentPage Title="Windows"> | ||
<VerticalStackLayout> | ||
<Button Text="Open Window" OnClick="OpenWindow" /> | ||
</VerticalStackLayout> | ||
</ContentPage> | ||
|
||
@code { | ||
[Inject] INavigation Navigation { get; set; } | ||
|
||
async Task OpenWindow() | ||
{ | ||
await Navigation.OpenWindow<WindowExample>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/BlazorBindings.Maui/Elements/Handlers/ApplicationWindowHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<object> _taskCompletionSource; | ||
|
||
public void AddChild(object child, int physicalSiblingIndex) | ||
{ | ||
TargetElement = child switch | ||
{ | ||
MC.Window window => window, | ||
MC.Page page => new MC.Window(page), | ||
_ => throw new InvalidOperationException($"Element '{child.GetType().FullName}' is not supported as an application root.") | ||
}; | ||
} | ||
|
||
public void ReplaceChild(int physicalSiblingIndex, object oldChild, object newChild) | ||
{ | ||
if (oldChild is MC.Window) | ||
throw new InvalidOperationException("Removing application root window is not supported."); | ||
|
||
TargetElement.Page = newChild.Cast<MC.Page>(); | ||
} | ||
|
||
public void RemoveChild(object child, int physicalSiblingIndex) | ||
{ | ||
if (child is MC.Window) | ||
throw new InvalidOperationException("Removing application root window is not supported."); | ||
|
||
TargetElement.Page = null; | ||
} | ||
|
||
public Task WaitForWindowAsync() | ||
{ | ||
if (TargetElement is not null) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
|
||
_taskCompletionSource ??= new(); | ||
return _taskCompletionSource.Task; | ||
} | ||
|
||
public MC.Window TargetElement { get; private set; } | ||
|
||
object IElementHandler.TargetElement => TargetElement; | ||
} |
25 changes: 0 additions & 25 deletions
25
src/BlazorBindings.Maui/Elements/Handlers/WindowHandler.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.