【发布时间】:2014-03-15 07:39:16
【问题描述】:
我正在为 windows phone 8 开发一个简单的地图应用程序。我使用 windows phone 工具包设置了多个图钉。我想在点击图钉项目时显示更多详细信息。 这是我的代码。
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<maps:Map Name="MyMap"
CartographicMode="Road" ColorMode="Light"
LandmarksEnabled="True" PedestrianFeaturesEnabled="True">
<toolkit:MapExtensions.Children>
<toolkit:MapItemsControl Name="allDatas">
<toolkit:MapItemsControl.ItemTemplate>
<DataTemplate>
<toolkit:Pushpin GeoCoordinate="{Binding Coordinate}"
Content="{Binding Name}"
Background="Green"
Foreground="Black"
Tap="Pushpin_Tap"/>
</DataTemplate>
</toolkit:MapItemsControl.ItemTemplate>
</toolkit:MapItemsControl>
</toolkit:MapExtensions.Children>
</maps:Map>
</Grid>
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
ObservableCollection<Data> datas = new ObservableCollection<Data>()
{
new Data() { Coordinate = new GeoCoordinate(22.832991,89.539921), Name = "H", Details = "Hospital", Address = "Address of Hospital" },
new Data() { Coordinate = new GeoCoordinate(22.845489,89.539406), Name = "P", Details = "Fire Station", Address = "Address of Fire"},
new Data() { Coordinate = new GeoCoordinate(22.818019,89.54563), Name = "F", Details = "Police Station", Address = "Address of Police"}
};
ObservableCollection<DependencyObject> children = MapExtensions.GetChildren(MyMap);
var obj = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl;
obj.ItemsSource = datas;
}
private void Pushpin_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Pushpin pushpin = sender as Pushpin;
if (pushpin.Content != null)
{ //Here i want to show details
MessageBox.Show(pushpin.Content.ToString());
}
}
【问题讨论】: