A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello,
I know you've already solved the issue, but I wanted to provide some information that might be helpful for others facing similar problems
Shell navigation in .NET MAUI serializes all parameters as URI strings for the underlying navigation system. When complex objects (non-primitive types) are passed via ShellNavigationQueryParameters, the framework attempts to convert them to string representations, which often results in:
- Loss of object data
- Default property values (nulls, zeros)
- Silent failures without error messages
Recommended Solution
Use a shared static service or singleton to store the object before navigation. Here's how:
1. Create a static data service
public static class NavigationDataStore
{
public static Observation CurrentObservation { get; set; }
}
2. Set the object before navigating
private async void TapGestureRecognizer_Tapped(object sender, TappedEventArgs e)
{
if (((VisualElement)sender).BindingContext is not Observation obs)
return;
NavigationDataStore.CurrentObservation = obs;
await Shell.Current.GoToAsync(nameof(DetailsPage));
}
3. Retrieve the object in the DetailsViewModel
public DetailsViewModel(ObservationService observationService)
{
Title = "Edit Observation";
_observationService = observationService;
Obs = NavigationDataStore.CurrentObservation;
CalcDone = false;
ComputeObsAsyncCommand = new AsyncRelayCommand(ComputeObsAsync);
UpdateObservationAsyncCommand = new AsyncRelayCommand(UpdateObservationAsync);
}
Alternative
If you need to persist data across sessions or support deep linking, consider serializing the object to JSON and passing it as a string, then deserializing it on the target page. However, this only works if the object is serializable and the data size is small.
I hope this helps clarify the issue.
References: