0

これは、Bing マップの画鋲用の私のコードです。

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

両方のプッシュピンに情報 (住所、電話番号) を追加するにはどうすればよいですか?

助けてください!

4

1 に答える 1

1

Pushpin のContentプロパティに何かを入れる必要があります。それは単純な文字列かもしれません

pin1.Content = "Hello, World.";

または、いくつかの子要素を持つパネルのようなより複雑なもの:

var panel = new StackPanel();
panel.Children.Add(...);
...
pin1.Content = panel;

2 番目のステップでは、おそらくDataTemplateを定義し、プッシュピンのContentTemplateプロパティに割り当てるか、そのDataTypeを設定して自動的に適用させます。

<UserControl.Resources>
    <DataTemplate DataType="local:Restaurant">
        <StackPanel>
            <TextBlock Text="{Binding Name}"/>
            <TextBlock Text="{Binding Address}"/>
        </StackPanel>
    </DataTemplate>
</UserControl.Resources>

Restaurantここで、アイテム データ クラス (ここではNameAddressプロパティを持つ) を画鋲のに割り当てるかバインドするだけですContent

于 2013-01-28T09:38:44.633 に答える