我不确定它是否解决了您的问题,但肯定解决了我的问题,并且对其他人也可能有所帮助。
public class MapControl : DependencyObject
{
#region Dependency properties
public static readonly DependencyProperty ZIndexProperty = DependencyProperty.RegisterAttached("ZIndex", typeof(int), typeof(MapControl), new PropertyMetadata(0, OnZIndexChanged));
#endregion
#region Methods
public static int GetZIndex(DependencyObject obj)
{
return (int)obj.GetValue(ZIndexProperty);
}
private static void OnZIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
ContentControl us = d as ContentControl;
if (us != null)
{
// returns null if it is not loaded yet
// returns 'DependencyObject' of type 'MapOverlayPresenter'
var parent = VisualTreeHelper.GetParent(us);
if (parent != null)
{
parent.SetValue(Canvas.ZIndexProperty, e.NewValue);
}
}
}
public static void SetZIndex(DependencyObject obj, int value)
{
obj.SetValue(ZIndexProperty, value);
}
#endregion
}
命名空间
xmlns:maps="using:Windows.UI.Xaml.Controls.Maps"
xmlns:mapHelper="using:yournamespace"
控制
<maps:MapControl>
<maps:MapItemsControl ItemsSource="...">
<maps:MapItemsControl.ItemTemplate>
<DataTemplate x:DataType="...">
<YourTemplate mapHelper:MapControl.ZIndex="{x:Bind ZIndex, Mode=OneWay}" />
</DataTemplate>
</maps:MapItemsControl.ItemTemplate>
</maps:MapItemsControl>
</maps:MapControl>