我今天正在努力解决一个问题。我有来自webservice的图钉的地图,我有这样的约束力:
string mynearjesonstring = e.Result.ToString();
var mynearitems = JsonConvert.DeserializeObject<RootObject>(mynearjesonstring);
NearSightingsItems.ItemsSource = mynearitems.sightings;
然后在XAML中:
<maps:MapItemsControl x:Name="NearSightingsItems" Width="450" Tap="NearSightingsItems_Tap" >
<maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<maps:Pushpin x:Name="NearSightingPushpin" Location="{Binding location}" Template="{StaticResource PushpinControlTemplate1}"/>
</DataTemplate>
</maps:MapItemsControl.ItemTemplate>
</maps:MapItemsControl>
运作良好,我可以看到所有的图钉。然后在pushpin上点击事件我想要更改一些TextBox.Text所以我尝试获取数据上下文...并且它等于null:
private void NearSightingsItems_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
var PushpinModel = (sender as Pushpin).DataContext as Sighting;
NameTextBlock.Text = PushpinModel.name;
}
也许问题是我的mynearitems.sightings在列表中?