I am trying to pass a query parameter from one ViewModel to another. I have a separate .Net MAUI solution where the query parameter is working, but for some reason the exact same setup won't work in my primary solution.
The navigation itself works and the listId has a value from MainViewModel navigation. I have the .NET MAUI Community Toolkit package installed. Have I missed a setup step?
MainViewModel.cs
[RelayCommand]
async Task GoToList(int listId)
{
await Shell.Current.GoToAsync($"{nameof(ListPage)}?ListId={listId}");
}
ListViewModel.cs
[QueryProperty("ListId", "ListId")]
public partial class ListViewModel : ObservableObject
{
[ObservableProperty]
int listId;
}
AppShell.cs
public AppShell()
{
InitializeComponent();
Routing.RegisterRoute(nameof(ListPage), typeof(ListPage));
}
MauiProgram.cs
public static MauiApp CreateMauiApp()
{
var builder = MauiApp.CreateBuilder();
builder.Services.AddTransient<MainPage>();
builder.Services.AddTransient<MainViewModel>();
builder.Services.AddTransient<ListPage>();
builder.Services.AddTransient<ListViewModel>();
return builder.Build();
}