Skip to content

INavigationParameterReceiver is null (Chapter 08) #1

@macik1423

Description

@macik1423

I am trying to implement solution with INavigationParameterReceiver from Chapter 08/Passing parameters section, but there is receiver is null here:

public class NavigationService : INavigationService
{
    public Task GoBack() => Shell.Current.GoToAsync("..");

    public Task GoToXXX(string name) => Navigate("xxx", 
        new ()
        {
            {
                "name", name
            }
        }
    );

    private static async Task Navigate(string pageName, Dictionary<string, object> parameters)
    {
        await Shell.Current.GoToAsync(pageName);
        if (Shell.Current.CurrentPage.BindingContext is INavigationParameterReceiver receiver) // here receiver is null
        {
            receiver.OnNavigatedTo(parameters);
        }
    }
}

Should I register INavigationParameterReceiver somehow?

Edit: I am debuging my code and Shell.Current.CurrentPage.BindingContext is null, but I don't know why.
I use DI to inject my VMs and here is the class for page:

public partial class XXXPage: ContentView
{
	public XXXPage()
	{
		InitializeComponent();
		BindingContext = ServiceHelper.GetService<XXXVM>();
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions