我正在使用 xamarin.forms 应用程序自定义地图显示数据库中的标记,当用户单击 pin 显示自定义信息窗口然后如果他单击此信息窗口导航到另一个活动显示更多信息。我使用了此链接上的示例,但无法编码从 pin 导航到活动,并在此活动中显示所有数据
我需要帮助,请
你可以通过 MessagingCenter
有正在运行的 GIF。
在 CustomMapRenderer
您应该使用 发送消息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 + "");
}
}
订阅此消息后,您可以打开导航页面。注意:您可以通过arg发送信息。
MessagingCenter.Subscribe<App, string>(App.Current, "OpenPage", (snd, arg) =>
{
Device.BeginInvokeOnMainThread(() => {
Navigation.PushAsync(new NavigationPage(new DetailsInfo(arg)));
});
});
有关于如何使用的文章MessagingCenter
。
https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center
这是我的演示。你可以参考一下。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句