I'm having trouble trying to figure out why I can't get a navigation property to pass to my page in Maui. I do understand that I shouldn't be able to see the property value in the constructor of the navigated to viewmodel but, even when I try to view the object in the actual navigated to page-behind code, it still appears null...
Passing the navigation property [MainViewModel.cs]
[RelayCommand]
async Task ShowPhotoDetails(PhotoDetailsFacade PhotoDetails)
{
Dictionary<string, object> navigationParameter = new Dictionary<string, object>();
navigationParameter.Add(nameof(PhotoDetailsFacade), PhotoDetails);
await Shell.Current.GoToAsync($"PhotoDataPage", navigationParameter); //navigation parameter is filled here, can see properties when debugging
}
PhotoDataPage is bound to a viewmodel... and has a binding to the viewmodel... [PhotoDataPage.xaml]
<ContentPage xmlns="[http://schemas.microsoft.com/dotnet/2021/maui](http://schemas.microsoft.com/dotnet/2021/maui)"
xmlns:x="[http://schemas.microsoft.com/winfx/2009/xaml](http://schemas.microsoft.com/winfx/2009/xaml)"
xmlns:viewmodel="clr-namespace:FishSnapData.ViewModel"
x:DataType="viewmodel:PhotoDataViewModel"
x:Class="MyProject.PhotoDataPage"
Title="PhotoDataPage">
...
<VerticalStackLayout BindingContext="{x:Type viewmodel:PhotoDataViewModel}"/><Image Source="{Binding PhotoDetails.FilePath}" HeightRequest="300" />
The viewmodel should receive the parameter... [PhotoDataViewModel.cs]
//[QueryProperty(nameOfPropertyThatWillRecieveTheData, parameterID (e.g. if there are multiple passed, this is the key in the dictionary))]
[QueryProperty("PhotoDetails", nameof(PhotoDetailsFacade))]
public partial class PhotoDataViewModel : ObservableObject
{
[ObservableProperty] //adds all the inotifyproperty goo needed for databinding and onchanged events
private PhotoDetailsFacade photoDetails;
public PhotoDataViewModel()
{
}...
Finally, the page hooks up the viewmodel. It is at this point that I think I should be able to view the properties of the PhotoDetails object but, they are still null [PhotoDataPage.xaml.cs]
public partial class PhotoDataPage : ContentPage
{
public PhotoDataPage(PhotoDataViewModel Vm)
{
InitializeComponent();
BindingContext = Vm; //browsing, the PhotoDetails object is still null here
}
Any suggestions to help me figure this out will be very much appreciated. Thanks