当我将ObservableCollection绑定到图钉数据的地图时,所有引脚都显示在左上角。我在一个简单的应用程序中复制了这个,不知道我做错了什么。有什么帮助吗?
<phone:PhoneApplicationPage
x:Class="PushpinApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True" xmlns:my="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<my:Map Name="map1">
<my:MapItemsControl ItemsSource="{Binding Stuff}">
<my:MapItemsControl.ItemTemplate>
<DataTemplate>
<my:Pushpin Location="{Binding Location}" Content="{Binding Name}" />
</DataTemplate>
</my:MapItemsControl.ItemTemplate>
</my:MapItemsControl>
</my:Map>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
public partial class MainPage : PhoneApplicationPage
{
public ObservableCollection<Thing> Stuff { get; set; }
// Constructor
public MainPage()
{
InitializeComponent();
Stuff = new ObservableCollection<Thing>();
Stuff.Add(new Thing() { Name = "one", Location = new GeoCoordinate(45.0, -110.0) });
Stuff.Add(new Thing() { Name = "two", Location = new GeoCoordinate(40, -100) });
DataContext = this;
}
}
public class Thing
{
public string Name { get; set; }
public Location Location { get; set; }
}
答案 0 :(得分:2)
为什么“位置”属性的类型为Location
而不是GeoCoordinate
?
另外,请尝试将MapItemsControl
放入MapLayer
。
<map:Map CredentialsProvider="Your_Key">
<map:MapLayer>
<map:MapItemsControl ItemsSource="{Binding Stuff}">
<map:MapItemsControl.ItemTemplate>
<DataTemplate>
<map:Pushpin Location="{Binding Location}" Content="{Binding Name}" />
</DataTemplate>
</map:MapItemsControl.ItemTemplate>
</map:MapItemsControl>
</map:MapLayer>
</map:Map>