I tried to pass an ImageSource object to another page via shell navigation.
When I call
await Shell.Current.GoToAsync($"{nameof(FullScreenImagePage)}?",
new Dictionary<string, object>
{
["TempImageSource"] = TempPhotoPoint.ExamplePicture
});
I get the following Exception: System.InvalidCastException: 'Object must implement IConvertible.'
ExamplePicture is of type ImageSource.
The FullScreenImagePage has a viewmodel which contains
[QueryProperty(nameof(TempImageSource), nameof(TempImageSource))]
and
[ObservableProperty] ImageSource tempImageSource;
The viewmodel is linked to the page by using BindingContext. When I pass the TempPhotoPoint object instead, which contains an ImageSource, everything works fine. How is it possible to pass the ImageSource object only?
I don't know why that doesn't work, but you can work around it by implementing method
ApplyQueryAttributes, as shown in Process navigation data using a single method.Be sure to add
: IQueryAttributableto your viewmodel class declaration, so Maui knows to use that method.In the method, you specify the conversion: