在我继续使用它们的同时,如何命名我的不同针脚?

时间:2016-01-02 03:07:58

标签: c# forms xamarin maps

当我这样做的时候:

                var ourPin = new Pin {

                    //info

                };

                ourPin.Clicked += (sender, args) => {
                //pushasync
                };

                map.Pins.Add (ourPin);

它有效但如果我尝试在add()中添加另一个引脚到我的地图,我只能输入1个引脚。所以我这样做了,但我不知道我应该如何命名每一个引脚:

            map.Pins.Add (new Pin {

            //info

            });
            map.Pins.Add(new Pin {

            //info

            });

            //how can i pushasync each pin?

使用这种方法我得到了两个引脚但是如上所述,我如何命名每一个引脚,以便我可以用每个引脚制作一个Clickfunction?

1 个答案:

答案 0 :(得分:2)

var pin = new Pin();
pin.Label = "Pin A";
pin.Address = "blah";
pin.Position = new Position(x1,y1);
pin.Clicked += Pin_Clicked;

map.Pins.Add(pin);

pin = new Pin();
pin.Label = "Pin B";
pin.Address = "blah";
pin.Position = new Position(x2,y2);
pin.Clicked += Pin_Clicked;

map.Pins.Add(pin);

pin = new Pin();
pin.Label = "Pin C";
pin.Address = "blah";
pin.Position = new Position(x3,y3);
pin.Clicked += Pin_Clicked;

map.Pins.Add(pin);

void Pin_Clicked (object sender, EventArgs e)
{
    Pin pin = (Pin)sender;

    // now pin is the Pin that was clicked, look at it's properties
    // to determine which pin and act accordingly
}