navigationuno

UNO Navigator.NavigateViewModelAsync<> not passing data as part of NavigationEventArgs


I am using the UNO Navigation in a windows and wasm app. In my app, I am implementing a simple Master-Detail pattern using Pages for both the Master and Detail. On the Master page there is a ListView. When an item is selected, I fire a Command to navigate to the Detail Page. I want to pass some objects to the Detail page. This is my code:

private async Task OnEditLocation()
{
    if (this.Navigator != null && SelectedLocation != null)
    {
        var navigationParameters = new Dictionary<string, object>
        {
            {"SelectedLocation", SelectedLocation },
            {"LocationList", Locations }
        };

        await Navigator.NavigateViewModelAsync<LocationViewModel>(sender:this,data:navigationParameters,cancellation:CancellationToken.None);
    }
}

On the Detail Page Code behind, I am capturing the OnNavigatedTo(NavigationEventArgs e) as follows:

protected override async void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    VM = this.DataContext as LocationViewModel;
    if (VM != null)
    {
        if (e.Parameter is IDictionary<string,object> parameters)
        {
            if (parameters.ContainsKey("SelectedLocation")) 
                VM.SelectedLocation = parameters["SelectedItem"] as FoodTruckLibrary.DataModels.Location;
        }
        
    }
}

The issue is that e.Parameter is always null. I have tried Navigator.NavigateDateAsync too, but with the same results.


Solution

  • Well it does work. I am able to pass a simple object, Guid, string, etc and it shows up as a parameter in the NavigationEventArgs. Doesn't seem to work with a Dictionary object.