2011-02-02 96 views
1

如何設置UserControl的ZIndex? 我試圖Silverlight設置UserControl的ZIndex

Canvas.SetZIndex((Tile)sender, 99); 
((Tile)sender).SetValue(Canvas.ZIndexProperty, 99); 

瓷磚是我有一個矩形,它是實際出現在屏幕上的用戶控件內我的用戶 的名稱。 我也曾嘗試

編輯:

這裏是爲我的用戶

<UserControl x:Class="Carcassonne.Tile" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    d:DesignHeight="76" d:DesignWidth="76"> 

    <Canvas x:Name="LayoutRoot" Background="Transparent"> 
     <Rectangle x:Name="rect" 
        Width="76" Height="76" 
        HorizontalAlignment="Left"> 
      <Rectangle.Fill> 
       <ImageBrush x:Name="tileImage"> 
        <ImageBrush.RelativeTransform> 
         <RotateTransform x:Name="rotation" CenterX="0.5" CenterY="0.5" Angle="0" /> 
        </ImageBrush.RelativeTransform> 
       </ImageBrush> 
      </Rectangle.Fill> 
     </Rectangle> 
    </Canvas> 
</UserControl> 
+0

您是否位於Canvas面板內的用戶控件?相對於你想要設置zIndex的是什麼?換句話說,你能提供你的標記的XAML代碼嗎? – 2011-02-02 20:13:48

+0

@Pavlo Glazkov是用戶控件位於「畫布」面板中。我有很多用戶控件,我需要將它們的Z-Index設置爲相對於主畫布或相互之間的關係。請在我的開場白中看到我的編輯。 – Arizona1911 2011-02-02 20:59:54

回答

1

這裏的XAML是一些假設:

  • 你有一些外部用戶控件或頁。
  • 此外部UserControl包含一個Canvas。
  • 這個畫布反過來有幾個直接的孩子,這是你的Carcassonne.Tile控制的實例。
  • 您已將附加事件處理程序添加到每個切片左下鼠標事件中,以便將受影響的切片移動到上面。

該既然如此你已經使用應該工作的代碼:=

Canvas.SetZIndex((Tile)sender, 99); 

除非你點擊他們也有99 Z-指數結束了其他瓷磚。你需要的是保持共同使用的最後一個Zindex值,然後每次事件發生時增加和使用它的值。

這個答案可能沒有幫助,因爲所有的假設中可能有一個或多個錯誤。如果你可以在你的問題中更具描述性,可以找到更好的匹配答案。