Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.1K
Vistas
.Net MAUI - AppShell navigation & dependency injection

I'm playing around with .Net Maui, AppShell and dependency injection.

I try to call a page with a constructor which takes the ViewModel of this page as parameter.

The constructor looks like this:

public AuthenticationPage(AuthenticationViewModel viewModel)
{
    InitializeComponent();
    BindingContext = viewModel;
}

In my MauiProgram.cs I registered both, the page and the VM

builder.Services.AddSingleton<AuthenticationViewModel>();
builder.Services.AddSingleton<AuthenticationPage>();

My App.xaml.cs looks like this:

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
        MainPage = new AppShell();
    }
}

And my AppShell.xaml looks like this:

<Shell  xmlns="http://schemas.microsoft.com/dotnet/2021/maui" 
           xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
           xmlns:pages="clr-namespace:DeepBlue.Pages"
           xmlns:auth="clr-namespace:DeepBlue.Pages.Authentication"
           x:Class="DeepBlue.AppShell">

    <!-- Login and Registration Page -->
    <ShellContent Route="login"
                  ContentTemplate="{DataTemplate auth:AuthenticationPage}">
    </ShellContent>

    <!-- Main Page -->
    <FlyoutItem Route="main"
                FlyoutDisplayOptions="AsMultipleItems">
        <ShellContent Route="dashboard"
                      ContentTemplate="{DataTemplate pages:DashboardPage}"
                      Title="Home" />
    </FlyoutItem>

</Shell>

Now when I execute my Project, I get the following error:

System.MissingMethodException: 'No parameterless constructor defined for type 'DeepBlue.Pages.Authentication.AuthenticationPage'.'

Could someone please tell me why the dependency injection does not work in this case?

If I don't implement the AppShell, everthing is working fine.... I can call AuthenticationPage as MainPage via injection from my App.xaml.cs like this:

public App(AuthenticationPage page)
{
    InitializeComponent();
    MainPage = page
}

Thanks, Phil

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Shell (and DataTemplates that is associated) does not have support for dependency injection (yet). Issues on the repository are opened here and here. And at the time of writing this answer a PR is open that adds this functionality. You can track the progress of that here.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda