1

当我尝试通过模板在 Windows Phone 8 中将用户位置标记添加到我的地图时,所有点都出现在地图的左上角。我确信我有不同的位置这是我的代码:

            <maps:Map x:Name="myMap" Center="{Binding CenterPoint}" ZoomLevel="5">
            <toolkit:MapExtensions.Children>
                    <ItemsControl ItemsSource="{Binding AllLocations}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <Grid/>
                            </ItemsPanelTemplate>
                        </ItemsControl.ItemsPanel>
                        <ItemsControl.ItemTemplate>
                            <DataTemplate>
                            <toolkit:MapChildControl>
                                <toolkit:UserLocationMarker Background="Blue" Foreground="Green" GeoCoordinate="{Binding coordinate,Converter={StaticResource GeoCoordinateConverter}}"/>
                            </toolkit:MapChildControl>
                            </DataTemplate>
                        </ItemsControl.ItemTemplate>

                    </ItemsControl>
            </toolkit:MapExtensions.Children>

        </maps:Map>
4

1 回答 1

6

不幸的是,在 XAML 中定义绑定不起作用。不知道为什么。- 可能与在运行时解析和构建 XAML 的方式有关。

但是,您可以在代码中设置绑定,它会起作用。

这是来自一个工作应用程序:

<map:Map x:Name="TheMap">
    <toolkit:MapExtensions.Children>
        <toolkit:MapItemsControl>
            <toolkit:MapItemsControl.ItemTemplate>
                <DataTemplate>
                    <toolkit:Pushpin GeoCoordinate="{Binding Converter={StaticResource PinToGeoCoordinateConverter}}"
                                        Content="{Binding Name}" />
                </DataTemplate>
            </toolkit:MapItemsControl.ItemTemplate>
        </toolkit:MapItemsControl>
    </toolkit:MapExtensions.Children>
</map:Map>

Loaded页面事件(在后面的代码中)

private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
    this.Loaded -= OnLoaded;

    // Have to set up the ItemSource explicitly - unfortunately this doesn't work if set in XAML :(
    var children = MapExtensions.GetChildren(TheMap);
    var obj = children.FirstOrDefault(x => x is MapItemsControl) as MapItemsControl;

    obj.ItemsSource = ViewModel.Pins;
}
于 2013-10-02T15:22:24.020 回答