Skip to content

Instantly share code, notes, and snippets.

@usausa
Last active June 20, 2022 07:37
Show Gist options
  • Save usausa/510d6c94102fd8b954a3ae2935eaf7c2 to your computer and use it in GitHub Desktop.
Save usausa/510d6c94102fd8b954a3ae2935eaf7c2 to your computer and use it in GitHub Desktop.
MAUI WindowOverlay
public sealed class LoadingOverlay : WindowOverlay
{
public LoadingOverlay(IWindow window)
: base(window)
{
AddWindowElement(new LoadingElementOverlay());
EnableDrawableTouchHandling = true;
}
private class LoadingElementOverlay : IWindowOverlayElement
{
public void Draw(ICanvas canvas, RectF dirtyRect)
{
// Grayed out screen
canvas.FillColor = Color.FromRgba(0, 0, 0, 64);
canvas.FillRectangle(dirtyRect);
}
public bool Contains(Point point)
{
// All touch events are handled by LoadingOverlay
return true;
}
}
}
public partial class MainPage
{
public MainPage()
{
InitializeComponent();
}
private async void Button_OnClicked(object? sender, EventArgs e)
{
var window = GetParentWindow();
var loading = new LoadingOverlay(window);
window.AddOverlay(loading);
await Task.Delay(3000);
window.RemoveOverlay(loading);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment