简体   繁体   English

确定导航到活动xamarin.forms的标记

[英]determine the marker that navigate to activity xamarin.forms

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. 我正在研究xamarin.forms应用程序自定义地图,当用户点击pin显示自定义信息窗口时显示来自数据库的标记然后如果他点击此信息窗口导航到另一个活动显示更多信息。 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 您可以通过MessagingCenter实现它

There is running GIF. 有运行GIF。

在此输入图像描述

In CustomMapRenderer CustomMapRenderer

You should send the message with MessageCenter . 您应该使用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. 订阅此消息时,您可以打开导航页面。注意:您可以通过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 . 有关于如何使用MessagingCenter文章。

https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center

Here is my demo. 这是我的演示。 You could refer to it. 你可以参考它。

https://github.com/851265601/MapUseMessageCenter https://github.com/851265601/MapUseMessageCenter

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM