Skip to content

A decent free navigation system for .NET MAUI apps.

License

Notifications You must be signed in to change notification settings

naveasy/Naveasy

Repository files navigation

Naveasy

It it works with:

  • .NET MAUI
  • Microsoft.Extensions.DependencyInjection
  • MAUI NavigatonPage.
  • MAUI FlyoutPage (check the samples to see how it works).

Build

Get Started

  1. Install it from nuget.org Static Badge

  2. Add the following namespace to your MauiProgram.cs:
    using Naveasy;

  3. Call .UseNaveasy() on your AppBuilder and then register your Views with it's corresponding ViewModels the your Service Collection by calling AddTransientForNavigation like described bellow.

public static class MauiProgram
{
    public static MauiApp CreateMauiApp()
    {
        var builder = MauiApp.CreateBuilder();
            
        builder.UseMauiApp<App>()
               .UseNaveasy();

        builder.Services
            .AddTransientForNavigation<LoginPage, LoginPageViewModel>()
            .AddTransientForNavigation<HomePage, HomePageViewModel>()
            .AddTransientForNavigation<ProductsPage, ProductsPageViewModel>()
            .AddTransientForNavigation<DetailsPage, DetailsPageViewModel>();

        return builder.Build();
    }
}
  1. Change your App.xaml.cs to assign a new NavigationPage to the MainPage and then use the NavigationService to navigate to the page you want's to.
public partial class App : Application
{
    public App(INavigationService navigationService)
    {
        InitializeComponent();

        //If you wanna navigate to page wraping it into a MAUI's NavigationPage use the Naveasy's
        //generice interface INavgiationPage<YourPageViewModel> like in the example bellow.
        navigationService.NavigateAsync<INavgiationPage<LoginPageViewModel>>();

        //otherwise use it like this:
        //navigationService.NavigateAsync<LoginPageViewModel>();
    }
}

You can refer to the sample that we have here on this repo to have a more in depth understanding of how you can navigate from one page to another and also how to handle the various page lifecycle events. You can optionaly implement the following handy base class which provides the various page lifecicle events that you would care about:

public class ViewModelBase : BindableBase, IInitialize, IInitializeAsync, INavigatedAware, IDestructible
{
    public virtual void OnInitialize(INavigationParameters parameters)
    {
    }

    public virtual Task OnInitializeAsync(INavigationParameters parameters)
    {
        return Task.CompletedTask;
    }

    public virtual void OnNavigatedFrom(INavigationParameters navigationParameters)
    {
    }

    public virtual void OnNavigatedTo(INavigationParameters navigationParameters)
    {
    }

    public virtual void Destroy()
    {
    }
}

Fell free to contribute.

There's No support for MAUI AppShell until MSFT trully fixes the following issues: dotnet/maui#7354 dotnet/maui#21814 dotnet/maui#21816

This library was inpired on the Dotnet Foundation version of PRISM.

About

A decent free navigation system for .NET MAUI apps.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages