将数据添加到图钉

时间:2013-01-28 09:32:00

标签: c# wpf visual-studio-2010 silverlight

这是我在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);

如何向图钉添加信息(地址,电话号码)?

请帮忙!

1 个答案:

答案 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此处具有NameAddress属性)分配或绑定到图钉Content即可