ShellInject 3.0.11
See the version list below for details.
dotnet add package ShellInject --version 3.0.11
NuGet\Install-Package ShellInject -Version 3.0.11
<PackageReference Include="ShellInject" Version="3.0.11" />
<PackageVersion Include="ShellInject" Version="3.0.11" />
<PackageReference Include="ShellInject" />
paket add ShellInject --version 3.0.11
#r "nuget: ShellInject, 3.0.11"
#:package ShellInject@3.0.11
#addin nuget:?package=ShellInject&version=3.0.11
#tool nuget:?package=ShellInject&version=3.0.11
ShellInject
ShellInject simplifies navigation and data transfer between ViewModels in .NET MAUI applications by leveraging the power of Shell Navigation combined with robust Dependency Injection. This package eliminates the need to manually register routes or ViewModels in your services, as ShellInject automatically handles route registration and ViewModel bindings for you.
With a single-line setup, ShellInject enhances maintainability and reduces boilerplate code, setting the BindingContext dynamically based on the ViewModelType property defined in XAML. This enables effortless parameter passing, lifecycle management, and seamless ViewModel interactions, making it ideal for applications with complex navigation flows or multi-page structures.
Setup
MauiProgram.cs
To enable ShellInject and integrate its features into your app, add the .UseShellInject()
line of code in your MauiProgram.cs
file after registering your app’s services and interfaces:
var builder = MauiApp.CreateBuilder();
builder
.UseMauiApp<App>()
.RegisterServices()
.UseShellInject();
return builder.Build();
Note: For now, it is recommended to add the .UseShellInject()
after all your services have been registered.
Usage
ViewModels
Ensure your ViewModels inherit from ShellInjectViewModel
to handle navigation events and parameter passing. You can override the following methods based on your needs:
DataReceivedAsync(object? parameter)
– Triggered when data is passed to the ViewModel.ReverseDataReceivedAsync(object? parameter)
– Handles data returned when navigating back from a page.
These two methods require the xaml markup shown below in order for them to trigger.
OnAppearing()
– Called when the page is about to appear.OnDisappearing()
– Called when the page is about to disappear.
ContentPage
In your ContentPage.xaml
file, specify the ViewModel to bind by setting the ViewModelType
property. This ensures that the correct ViewModel is injected and bound to the page:
xmlns:ez="clr-namespace:ShellInject;assembly=ShellInject"
ez:ShellInjectPageExtensions.ViewModelType="{x:Type vm:MainViewModel}"
Optionally you can set up listeners for OnAppearing and OnDisappearing events
ez:ShellInjectPageExtensions.OnAppearingCommand="{Binding OnAppearingCommand}"
ez:ShellInjectPageExtensions.OnDisappearingCommand="{Binding OnDisAppearingCommand}"
Navigation
ShellInject provides extension methods to simplify navigation between pages and passing parameters between ViewModels:
Example:
await Shell.Current.PushAsync(typeof(DetailsPage), new { id = 123, name = "John" });
Available navigation methods:
Task PushAsync(this Shell shell, Type pageType, object? parameter, bool animate = true)
Task PopAsync(this Shell shell, object? parameter = null, bool animate = true)
Task PopToAsync(this Shell shell, Type pageType, object? parameter = null, bool animate = true)
Task PopToRootAsync(this Shell shell, object? parameter = null, bool animate = true)
Task ChangeTabAsync(this Shell shell, int tabIndex, object? parameter = null, bool popToRootFirst = true)
Task PushMultiStackAsync(this Shell shell, List<Type> pageTypes, object? parameter = null, bool animate = true, bool animateAllPages = false)
Task PushModalAsync(this Shell shell, ContentPage page, object? parameter = null, bool animate = true)
Task PushModalWithNavigationAsync(this Shell shell, Type pageType, object? parameter = null, bool animate = true)
Task ReplaceAsync(this Shell shell, Type? pageType, object? parameter = null, bool animate = true)
Helper methods:
This method looks for the specified Page on the stack and sends the data using the ReverseDataReceivedAsync method.
Task SendDataToPageAsync(this Shell shell, Type? page, object data)
TODO List:
- Update Sample Project
- Add Unit Tests
- Setup CI/CD
- Add Support for Popups?
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-android34.0 is compatible. net8.0-browser was computed. net8.0-ios was computed. net8.0-ios18.0 is compatible. net8.0-maccatalyst was computed. net8.0-maccatalyst18.0 is compatible. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net8.0-windows10.0.19041 is compatible. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
-
net8.0-android34.0
- No dependencies.
-
net8.0-ios18.0
- No dependencies.
-
net8.0-maccatalyst18.0
- No dependencies.
-
net8.0-windows10.0.19041
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
3.1.7 | 98 | 6/21/2025 |
3.1.6 | 381 | 4/8/2025 |
3.1.5 | 159 | 4/3/2025 |
3.1.4 | 149 | 3/20/2025 |
3.1.3 | 77 | 3/15/2025 |
3.1.2 | 135 | 2/13/2025 |
3.1.1 | 125 | 2/5/2025 |
3.1.0 | 127 | 2/3/2025 |
3.0.11 | 121 | 1/31/2025 |
3.0.10 | 103 | 1/29/2025 |
3.0.9 | 99 | 1/27/2025 |
3.0.8 | 95 | 1/27/2025 |
3.0.7 | 106 | 1/27/2025 |
3.0.6 | 100 | 1/23/2025 |
3.0.5 | 108 | 1/17/2025 |
3.0.4 | 429 | 11/1/2024 |
3.0.3 | 160 | 10/23/2024 |
3.0.2 | 104 | 10/22/2024 |
3.0.1 | 113 | 10/21/2024 |
3.0.0 | 116 | 10/20/2024 |
Fixed Package dependency Issues when projects are trying to install