i navigate from blazor page to .Net maui page using this code App.Current.MainPage.Navigation.PushModalAsync(new QRcodeSCanner());
,Then i click on button that fire this code to navigate back to blazor page Navigation.PopModalAsync();
...BUUUT, i want to capture this pop in my blazor page when it happens to do some test ,so it is possible ????
Asked
Active
Viewed 1,111 times
1

Ilyes Sahbeni
- 41
- 5
-
What does 'capture this pop in my blazor page' mean? Can you provide more information? – Guangyu Bai - MSFT Aug 19 '22 at 05:44
-
hey @GuangyuBai-MSFT thank you for following up , i mean i need and event in blaror page or something when i came from maui to blazor . – Ilyes Sahbeni Aug 20 '22 at 21:55
2 Answers
1
Heyyy everyone i find the solution : i build a class responsible for the navigation
public class NavigationHelper
{
private readonly NavigationManager _navigationManager;
public NavigationHelper( NavigationManager navigationManager)
{
_navigationManager = navigationManager;
}
public void Navigate(string Url)
{
_navigationManager.NavigateTo(Url);
}
}
In the Razor page that navigate from to the Maui page
@{/*Dependency Injection of NavigationManager*/}
@inject NavigationManager navigationManager
//pass the navigation manger injected to the constructor of this class
NavigationHelper NavigationHelper = new(navigationManager);
await App.Current.MainPage.Navigation.PushModalAsync(new TheMuaiPageName(NavigationHelper));
Then in the Maui code behind class
private readonly NavigationHelper? _navigationHelper;
public QRcodeSCanner(NavigationHelper NavigationHelper)
{
InitializeComponent();
_navigationHelper = NavigationHelper;
}
public async void Method(object sender, EventArgs args)
{
//this is to back to blazor page , then force the navigation to the desired page
Navigation.PopModalAsync();
_navigationHelper.Navigate("/OtherRazorPage");
}

Ilyes Sahbeni
- 41
- 5
0
Take a look at the documentation page for NavigationPage (https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/navigationpage).
The NavigationPage class has three events, one of which is Popped. "Popped is raised when when a page is popped from the navigation stack." Will that work for you?

Jim Marquardt
- 3,959
- 1
- 12
- 21
-
I have visited this page, but there seems to be no mention on how to handle the events (such as popped) from the originating page. – gouderadrian Oct 25 '22 at 08:15