2013-03-16 34 views
0

我試圖讓我的彈出窗口小部件位於地圖的頂部,但設置Canvas.ZOrder沒有幫助。Silverlight ZOrder在Bing控件中不適用於我

這裏是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 =真(看其他點與zIndex的更高頂部)

enter image description here

+0

ZIndex是僅影響同一Panel的子項的相對值。因此,將其設置在項目DataTemplate內Canvas的某個子項上將毫無意義。你在哪裏設定?我無法在您的XAML中看到它。 – Clemens 2013-03-17 21:25:05

+0

我試圖將它設置在一個包圍ContentControl的邊框上,它不在XAML中,因爲我將其移除。在我的例子中,我應該這樣做,以便它生效? – katit 2013-03-17 22:03:52

+0

您可以在代碼後面的項目容器中設置它。您可以通過MapItemsControls的[ItemContainerGenerator](http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemcontainergenerator.aspx)獲取項目的容器。 – Clemens 2013-03-17 22:11:25

回答

1

爲了帶來正面的項目在MapItemsControl有必要設定該項目的Z-索引容器。您可以通過從MapItemsControl的ItemContainerGenerator中檢索項目容器來在代碼後面執行此操作。

如果您不需要,可以將附加的幫助屬性應用於DataTemplate中的頂級容器(Canvas)以獲取地圖項目。由於此Canvas是項目容器的直接子項,所以助手屬性必須設置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現在你可以或許通過使用適當的輔助屬性綁定到你的虛擬機性能,一個綁定轉換器:

<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> 
+0

嗯..我想起它,它可能無法解決我的問題。我有點(小圓圈)和實際面板,作爲同一數據模板的一部分可見。給這個模板ZOrder會爲地圖上的所有項目執行此操作,並且會出現同樣的問題。我應該將面板放在單獨的畫布中,並將不同的ZOrder放在面板和圓點上嗎? – katit 2013-03-18 20:25:51

+1

以這種方式設置ZIndex將使實際項目位於前面,即高於所有其他項目。因此,頂點上的點和邊界將放置在MapItemsControl中的其他任何位置上。當然綁定源屬性必須專門爲「前」項目設置。 – Clemens 2013-03-18 20:28:57

+0

我明白了。所以我必須操縱特定項目的ZOrder。非常感謝您幫助我解決這個問題。我會標記爲答案,但我實際上以不同的方式解決了它(更簡單的IMO)。我只用另一個MapItemsControl彈出面板。所以第一個繪製點,第二個繪製隱形面板。很棒! – katit 2013-03-18 20:37:51

相關問題