1

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 ????

2 Answers2

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");
    }
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