0
我有以下XAML代码:获得母公司在XAML
<maps:Map Name="PlaygroundMap" Credentials="YOUR_BING_MAPS_KEY">
<maps:MapItemsControl
x:Name="PlaygroundMapItems"
my:MapExt.ClusteredItemsSource="{Binding Locations}"
ItemTemplate="{StaticResource PinTemplate}"/>
</maps:Map>
而且ClusteredItemsSource是我自己的附加属性,用下面的代码(仅重要部分显示):
private static void OnItemsReceived(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var mapItemsControl = d as MapItemsControl;
if(mapItemsControl == null) return;
var map = VisualTreeHelper.GetParent(mapItemsControl); // this is always NULL
var map2 = mapItemsControl.Parent; // this is always NULL
var items = e.NewValue as IEnumerable<Location>;
mapItemsControl.ItemsSource = items;
}
所以我要求是在OnItemsReceived方法中有MAP引用。我认为这很容易,因为如果你再次检查XAML,你会看到mapItemsControl是Map的子项(或者map是mapItemsControl的父项)。
但不知怎的变量映射& map2总是NULL。这是正常的行为还是?另外,如果这种“父”方法不起作用,你能告诉我什么是我在MapItemsControl中获取Map引用的其他选项(确切地说,在我的自定义附属属性中获取地图引用)。
顺便说一句,我使用Bing Maps SDK for WinRT。
谢谢。你最后一句话就是我在结尾做的:) – rjovic