From 7382b5a6af8d342d1795b9cffd909a23bd048ccf Mon Sep 17 00:00:00 2001 From: David Britch Date: Mon, 2 Oct 2023 10:07:16 +0100 Subject: [PATCH] TryDispatchAsync on BlazorWebView --- docs/user-interface/controls/blazorwebview.md | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/user-interface/controls/blazorwebview.md b/docs/user-interface/controls/blazorwebview.md index 86a7b793a3..f833fbb0ad 100644 --- a/docs/user-interface/controls/blazorwebview.md +++ b/docs/user-interface/controls/blazorwebview.md @@ -17,7 +17,7 @@ The .NET Multi-platform App UI (.NET MAUI) has a `TryDispatchAsync` method that calls a specified `Action` asynchronously and passes in the scoped services available in Razor components. This enables code from the native UI to access scoped services such as `NavigationManager`: + +```csharp +private async void MyMauiButtonHandler(object sender, EventArgs e) +{ + var wasDispatchCalled = await _blazorWebView.TryDispatchAsync(sp => + { + var navMan = sp.GetRequiredService(); + navMan.CallSomeNavigationApi(...); + }); + + if (!wasDispatchCalled) + { + // Consider what to do if it wasn't called - that's up to your app to decide + } +} +``` + +::: moniker-end