0

我正在尝试使我的弹出窗口小部件位于地图的顶部,但设置 Canvas.ZOrder 并没有帮助。

这是 XAML:

<m:Map x:Name="MainMap"
            Margin="0,6,3,3"
            ZoomLevel="{Binding MapZoomLevel, Mode=TwoWay}"
            Center="{Binding MapCenter, Mode=TwoWay}"
            CopyrightVisibility="Collapsed"
            CredentialsProvider="{Binding BingCredentialsProvider}"
            UseInertia="True" 
            Mode="Road" Grid.Column="2" Grid.Row="1">
            <m:MapItemsControl ItemsSource="{Binding Source={StaticResource WorkLayerData}}">
                <m:MapItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Canvas
                            m:MapLayer.Position="{Binding Location}">
                            <Button                                
                                Width="{Binding PushpinWidth}" Height="{Binding PushpinWidth}"
                                Margin="{Binding PushpinMargin}"
                                Style="{StaticResource LooklessButtonStyle}"
                                Command="{Binding DataContext.SelectedPushpinChangedCommand, ElementName=LayoutRoot}"
                                CommandParameter="{Binding}"
                                Cursor="Hand">
                                <Ellipse
                                    Width="{Binding PushpinWidth}" Height="{Binding PushpinWidth}" Stroke="Black" Fill="{Binding IsGPSDataRecent, Converter={StaticResource BoolToGreenRedBrushConverter}}" StrokeThickness="1">
                                    <ToolTipService.ToolTip>
                                        <TextBlock Text="{Binding DeviceId}" />
                                    </ToolTipService.ToolTip>
                                </Ellipse>
                            </Button>

                            <!-- Show black dot over actual GPS point -->
                            <Ellipse
                                Width="10" Height="10" Stroke="Black" Fill="Black" StrokeThickness="1"
                                Margin="-5,-5,0,0"
                                Visibility="{Binding IsSelected, Converter={StaticResource BoolToVisibilityConverter}}" />

                            <Border
                                Width="200"
                                BorderThickness="1" BorderBrush="DarkGray"
                                Visibility="{Binding IsSelected, Converter={StaticResource BoolToVisibilityConverter}}">
                                <Border.Effect>
                                    <DropShadowEffect BlurRadius="5"  Color="#FF000000" Opacity="0.5" ShadowDepth="2" />
                                </Border.Effect>
                                <ContentControl Template="{StaticResource TrackedAssetControlTemplate}" />
                            </Border>
                        </Canvas>                                               
                    </DataTemplate>
                </m:MapItemsControl.ItemTemplate>
            </m:MapItemsControl>
        </m:Map>

我试图在边界上设置 ZIndex 但没有运气。这是 IsSelected = true 时的外观(请参阅顶部 ZIndex 较高的其他点)

在此处输入图像描述

4

1 回答 1

1

为了将 MapItemsControl 中的项目置于前面,需要设置项目容器的 ZIndex。您可以通过从 MapItemsControl 的ItemContainerGenerator检索项目容器在代码中执行此操作。

如果您不希望这样,您可以将附加的帮助器属性应用到地图项的 DataTemplate 中的顶级容器(Canvas)。由于此 Canvas 是项目容器的直接子级,因此 helper 属性必须设置 Canvas 的可视父级的 ZIndex。如果这听起来很奇怪,这里是附加属性的代码,在一个名为 MapItem 的帮助器类中:

public class MapItem
{
    public static readonly DependencyProperty ZIndexProperty =
        DependencyProperty.RegisterAttached("ZIndex", typeof(int),
            typeof(MapItem), new PropertyMetadata(ZIndexChanged));

    public static int GetZIndex(DependencyObject obj)
    {
        return (int)obj.GetValue(ZIndexProperty);
    }

    public static void SetZIndex(DependencyObject obj, int value)
    {
        obj.SetValue(ZIndexProperty, value);
    }

    private static void ZIndexChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
    {
        // set ZIndex on parent of obj
        Canvas.SetZIndex((UIElement)VisualTreeHelper.GetParent(obj), (int)e.NewValue);
    }
}

在您的 DataTemplate 中,您现在可以将 helper 属性绑定到您的 VM 属性之一,或许可以使用适当的绑定转换器:

<DataTemplate x:Key="MapItemDataTemplate">
    <!-- setting the helper property MapItem.ZIndex on Canvas
         sets the Canvas.ZIndex property on the item container -->
    <Canvas local:MapItem.ZIndex="{Binding ...}">
        ...
    </Canvas>
</DataTemplate>
于 2013-03-18T18:43:10.607 回答