2011-02-02 97 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值,然后每次事件发生时增加和使用它的值。

这个答案可能没有帮助,因为所有的假设中可能有一个或多个错误。如果你可以在你的问题中更具描述性,可以找到更好的匹配答案。