Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调用Pin映射控件Xamarin forms pcl上的click事件_C#_Google Maps_Xamarin_Xamarin.forms_Portable Class Library - Fatal编程技术网

C# 调用Pin映射控件Xamarin forms pcl上的click事件

C# 调用Pin映射控件Xamarin forms pcl上的click事件,c#,google-maps,xamarin,xamarin.forms,portable-class-library,C#,Google Maps,Xamarin,Xamarin.forms,Portable Class Library,我正在网上查找,但找不到任何内容,我正在使用地图控件Xamarin forms pcl。 我必须说,当我点击地图上的Pin(谷歌地图)时,我找到了要触发的事件。 有人能给我建议吗?多谢各位 var map = new Map( MapSpan.FromCenterAndRadius( new Position(lat, lon), Distance.FromMiles(50)))

我正在网上查找,但找不到任何内容,我正在使用地图控件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);                        
                    }

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;
};

ref:

您还可以绑定到管脚列表?您的示例涉及单个对象,如何将事件连接到列表中的所有管脚?@Mr.Developer您需要为每个管脚分配相同的事件委托。。。您总是可以编写一个列表扩展名,通过refection执行赋值…可能会有所帮助