【问题标题】:call the click event on the Pin Map control Xamarin forms pcl在 Pin Map 控件上调用 click 事件 Xamarin forms pcl
【发布时间】:2016-11-16 14:06:32
【问题描述】:

我正在网上寻找但找不到任何东西,我正在使用 Map 控件 Xamarin forms pcl。 我必须说,当我点击地图(谷歌地图)上的 Pin 图时,我发现事件会触发。 谁能给我建议?谢谢。

var map = new Map(
                    MapSpan.FromCenterAndRadius(
                        new Position(lat, lon), Distance.FromMiles(50)))
                    {
                        IsShowingUser = true,
                        HeightRequest = CrossScreen.Current.Size.Height,
                        WidthRequest = CrossScreen.Current.Size.Width,
                        VerticalOptions = LayoutOptions.FillAndExpand
                    };

                    RGL_Locations = RGL_Locations.OrderByDescending(x => x.RGL_DateTime).ToList();

                    foreach (RGL_Locations item in RGL_Locations)
                    {
                        map.Pins.Add(new Pin { Type = PinType.Generic, Label = item.RGL_MCC_Numero_Serie_MS.ToString(), Position = new Position(item.RGL_Latitudine, item.RGL_Longitudine) });
                    }

                    map.Pins.Add(new Pin { Type = PinType.Generic, Label = "Io sono qui!", Position = new Position(lat, lon)});

                    var stack = new StackLayout { Spacing = 0 };
                    stack.Children.Add(map);
                    Content = stack;

解决方案:

foreach (RGL_Locations item in RGL_Locations)
                    {
                        var pin = new Pin
                        {   
                            Type = PinType.Place,
                            Position = new Position(item.RGL_Latitudine, item.RGL_Longitudine),
                            Label = "Clicca qui per aprire",
                            Address = "Numero di serie macchina: " + item.RGL_MCC_Numero_Serie_MS.ToString()
                        };

                        pin.Clicked += Pin_Clicked;

                        map.Pins.Add(pin);                        
                    }

【问题讨论】:

标签: c# google-maps xamarin xamarin.forms portable-class-library


【解决方案1】:

Xamarin.Forms.Map Pin 类有一个 Clicked 事件:

var position = new Position(32, -13); 
var pin = new Pin
{
    Type = PinType.Place,
    Position = position,
    Label = "custom pin",
    Address = "custom detail info"
};
pin.Clicked +=  (object sender, EventArgs e) =>
{
    var p = sender as Pin;
};

参考:Xamarin.Forms.Maps.Pin.Clicked

【讨论】:

  • 你也可以绑定到一个引脚列表?您的示例指的是单个对象,我该如何将事件连接到列表的所有引脚?
  • @Mr.Developer 您需要为每个 Pin 图分配相同的事件委托...您始终可以编写一个列表扩展来通过反射完成分配...
猜你喜欢
  • 1970-01-01
  • 2018-04-12
  • 1970-01-01
  • 1970-01-01
  • 2014-09-08
  • 2017-04-08
  • 2016-11-13
  • 2021-12-26
  • 1970-01-01
相关资源
最近更新 更多