Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I NavigationService to navigate to a page instead of PageModel #61

Open
tonyyip1969 opened this issue Dec 25, 2024 · 1 comment
Labels
needs-info Issue need more info from the author

Comments

@tonyyip1969
Copy link

I have below code currently, how do I achieve using NavigationService?

var page = new ScanQrCodePage(OnScanned, config =>
{
    
});

await Shell.Current.Navigation.PushAsync(page);  // <--  await _navigationService.GoToAsync(Navigation.Relative().Push(page));
@albyrock87
Copy link
Contributor

@tonyyip1969 if I understood your example correctly, you're trying to push a page which scans a QR code based on a configuration factory (second parameter I see there in the constructor).
When the QR code has been read, you expect the page to pop and invoke a callback on the previous page.

I would still suggest using a view model, but if you really want to use a simple page, here's what you can do:

  1. Remove arguments from page constructor
  2. Make sure your page is registered as Scoped in the DI
  3. In page constructor set BindingContext=this
  4. Create a class or record to hold your 2 arguments, for instance QRCodeCaptureIntent
  5. Implement IEnteringAware<QRCodeCaptureIntent> interface in your page (this is where you will receive the arguments)
  6. Use the standard Nalu navigation API providing your page type instead of the page model Navigation.Relative().Push<ScanQRCodePage>

This should work out of the box.
I haven't felt the need of pushing pages directly from MVVM pattern, but if you can tell a good reason for doing this, I can easily add the I*Aware support to pages too so that step 3 above can be avoided.

@albyrock87 albyrock87 added the needs-info Issue need more info from the author label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-info Issue need more info from the author
Projects
None yet
Development

No branches or pull requests

2 participants