这是我在Bing Map上的图钉代码。
MapLayer layer = new MapLayer();
Pushpin pin1 = new Pushpin();
GeoCoordinate geo = new GeoCoordinate();
geo.Latitude = 1.369963;
geo.Longitude = 103.849275;
pin1.Location = geo;
layer.Children.Add(pin1);
Pushpin pin2 = new Pushpin();
GeoCoordinate geo1 = new GeoCoordinate();
geo1.Latitude = 1.350678;
geo1.Longitude = 103.848224;
pin2.Location = geo1;
layer.Children.Add(pin2);
map1.Children.Add(layer);
如何向图钉添加信息(地址,电话号码)?
请帮忙!
答案 0 :(得分:1)
你必须在Pushpin的Content财产中加入一些东西。那可能是一个简单的字符串
pin1.Content = "Hello, World.";
或更复杂的东西,比如带有一些子元素的面板:
var panel = new StackPanel();
panel.Children.Add(...);
...
pin1.Content = panel;
在第二步中,您可以定义一个DataTemplate并将其分配给图钉的ContentTemplate属性,或者通过设置其DataType来自动应用它:< / p>
<UserControl.Resources>
<DataTemplate DataType="local:Restaurant">
<StackPanel>
<TextBlock Text="{Binding Name}"/>
<TextBlock Text="{Binding Address}"/>
</StackPanel>
</DataTemplate>
</UserControl.Resources>
现在,您只需将此商品数据类(Restaurant
此处具有Name
和Address
属性)分配或绑定到图钉Content
即可