Search code examples
xamarin.formscontentview

How to open a ContentPage from a ContentView?


I have a Xamarin.forms.Maps in a ContentView and I am using that view in a ListView. I need to open a new page when clicking the map.

I tried like below:

MapClicked="MapClicked"

private async void MapClicked(object sender, MapClickedEventArgs e)
{
    var item = (History)((Map)sender).BindingContext;
    await Navigation.PushModalAsync(new Pages.Page1());
}

When I tap the map these lines are triggering, but Page1 is not opening. So what is the exact way to open a ContentPage from a ContentView?

Reference: Xamarin Forms: How to bind the position value of Xamarin.forms.Maps inside the ListView?


Solution

  • You should have NavigationPage as root page to navigate. read more at: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/hierarchical