Last active
June 20, 2022 07:37
-
-
Save usausa/510d6c94102fd8b954a3ae2935eaf7c2 to your computer and use it in GitHub Desktop.
MAUI WindowOverlay
This file contains hidden or 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
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; | |
} | |
} | |
} |
This file contains hidden or 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
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