【问题标题】:How to add mouse click event on Push pins in Bing map metro app using C# and Xml?如何使用 C# 和 Xml 在 Bing 地图 Metro 应用程序中的图钉上添加鼠标单击事件?
【发布时间】:2013-01-17 20:57:10
【问题描述】:

我在 bing 地图上有多个动态图钉。我想在这些图钉上添加鼠标点击事件。告诉我我该怎么做。我正在使用 C# 和 XML 在 Windows 商店应用程序中工作。

【问题讨论】:

    标签: microsoft-metro windows-store-apps winrt-xaml bing-maps


    【解决方案1】:

    当您以编程方式添加图钉时,将公共事件处理程序Tapped 添加到每个图钉。当图钉被点击时,它将被调用,并且从sender 对象中,您可以区分每个图钉并做任何您喜欢的事情。

    //Suppose I have PushpinsCollection which is list of MyPushpin class. PushpinsCollection is generated dynamically
    public class MyPushpin
    {
        public int PinID { get; set; }
        public Pushpin Pin { get; set; }
        public Location PinLocation { get; set; }
    }
    
    //run foreach loop do add event hanlder and add to map
    //Here MyMap is Bing Map control
    foreach(var pushpin in PushpinsCollection)
    {
        var _pin = pushpin.Pin;
        _pin.Tapped += Pushpin_Tapped
        MapLayer.SetPosition(_pin, PinLocation);
        MyMap.Children.Add(_pin);
    }
    
    private void Pushpin_Tapped(object sender, TappedRoutedEventArgs e)
    {
        var TappedPin = (Pushpin)sender;
        //TODO: do whatever opetraion you want to with TappedPin
    }
    

    【讨论】:

      猜你喜欢
      • 2021-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多