.net maui Passing Multiple Parameters

John Rutherford 21 Reputation points
2025-07-17T06:29:11.5733333+00:00

Using Visual Studio Community 17.14.9

.Net9

Maui App

I have an app using MVVM with 8 pages and wish to pass 2 objects (ObsLocation class) and (string) from my ProjectSelectionPageViewModel to my LocationPageViewModel using the following code.

location = new ObsLocation
{
    Id = MaxId + 1, // Increment the Id for the new project
    ProjDescription = "MyProject",
    Latitude = "-10.4540",
    Longitude = "126.0150",
    AlignmentAngle = "28.2440",
    TimeZoneId = TimeZoneInfo.Utc.Id,
};
//save the Location information in the file
LocationService.SaveLocationAsync(location);
// now navigate to the LocationPage with this location
await Shell.Current.GoToAsync(nameof(LocationPage), true, new Dictionary<string, object>
{
    {"ObsLocation", location},
    {"ProjectType", "New"},
});
IsBusy = false;

The code on my LocationPageViewModel is

private string title = string.Empty;

public string Title
{
    get => title;
    set => SetProperty(ref title, value);
}

The ObsLocn value is passed correctly. However the ProjectType (string value) comes through as null.

Can any offer a solution please.

Developer technologies | C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. John Rutherford 21 Reputation points
    2025-07-17T06:46:45.0633333+00:00

    LocationViewModel code should be

    using CommunityToolkit.Maui.Alerts;
    using CommunityToolkit.Mvvm.ComponentModel;
    using CommunityToolkit.Mvvm.Input;
    using SunObs.Models;
    using SunObs.Services;
    using System.Collections.ObjectModel;
    namespace SunObs.ViewModel
    {
        [QueryProperty (nameof(Obslocn), "ObsLocation")]
        [QueryProperty(nameof(ProjectType), "ProjType")] 
        public partial class LocationViewModel : BaseViewModel
        {
            public ReadOnlyCollection<TimeZoneInfo> TimeZones { get; }
            [ObservableProperty]
            public required ObsLocation obslocn;
            [ObservableProperty]
            private string projectType;
    
    0 comments No comments

  2. John Rutherford 21 Reputation points
    2025-07-19T01:06:29.26+00:00

    Solved it myself. The ProjectType was not properly declared in ProjectSelectionPageViewModel


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.