I'm working on xamarin.forms application custom map shows markers from the database when the user click on pin show custom info window then if he clicks on this info window navigates to another activity show more information. I used the sample on this link and cannot code navigate from pin to activity with all data to show in this activity
I need help, please
You can achieve it by MessagingCenter
There is running GIF.
In CustomMapRenderer
You should send the message with MessageCenter
.
void OnInfoWindowClick(object sender, GoogleMap.InfoWindowClickEventArgs e)
{
var customPin = GetCustomPin(e.Marker);
if (customPin == null)
{
throw new Exception("Custom pin not found");
}
if (!string.IsNullOrWhiteSpace(customPin.Url))
{
var url = Android.Net.Uri.Parse(customPin.Url);
MessagingCenter.Send<App, string>(App.Current as App, "OpenPage", customPin.Address + "");
}
}
When you Subscribe this message, you can open the navigationpage.Note:You can send information by arg.
MessagingCenter.Subscribe<App, string>(App.Current, "OpenPage", (snd, arg) =>
{
Device.BeginInvokeOnMainThread(() => {
Navigation.PushAsync(new NavigationPage(new DetailsInfo(arg)));
});
});
There is article about how to use MessagingCenter
.
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center
Here is my demo. You could refer to it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.