WP 8.1 MapControl如何添加自定义图钉并以编程方式添加ItemSource?

时间:2015-08-20 18:14:29

标签: c# windows-phone-8.1

如何添加到我的地图控件自定义图钉? 我需要在我的针脚: TextBlock和Button

我尝试这样的事情:

<Maps:MapControl Grid.Row="2"
                    x:Name="MapControl"
                    MapServiceToken=""
                    Margin="0,0,0,0" >
                <Maps:MapItemsControl >
                    <Maps:MapItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <TextBlock Height="25" Text="{Binding Where}" Maps:MapControl.Location="{Binding Location}" />
                                <Button Content="MyButton" Maps:MapControl.Location="{Binding Location}" />
                            </Grid>
                        </DataTemplate>
                    </Maps:MapItemsControl.ItemTemplate>
                </Maps:MapItemsControl>
            </Maps:MapControl>

但是如何将DataSource或ItemsSource添加到我的MapItemsControl中? 我需要在后面的代码中执行此操作。

我的模特:

public class PinModel
    {
        public Geopoint Location { get; set; }
        public string Where { get; set; }
    }

如何做到这样:

List<PinModel> pins = new List<PinModel>();
MapControl.DataSource = pins?????(how can I do this?)

在我的地图上找到别针。

使用Windows Phone 8.1

Maps:MapControl
xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"

1 个答案:

答案 0 :(得分:1)

看看Shawn Kendrot的一个很好的教程,他的打击在这里:http://www.visuallylocated.com/post/2014/08/13/Bind-a-collection-of-items-to-the-Windows-Phone-MapControl.aspx

它底部有一个示例项目链接,可以让你整理出来。