Silverlight setting ZIndex of UserControl
How do I set the ZIndex of a UserControl? I have tried
Canvas.SetZIndex((Tile)sender, 99);
((Tile)sender).SetValue(Canvas.ZIndexProperty, 99);
Tile is the name of my UserControl I have a Rectangle inside the UserControl that is what actually appears on the screen. I have also tried
Canvas.SetZIndex(((Tile)sender).rect, 99);
((Tile)sender).rect.SetValue(Canvas.ZIndexProperty, 99);
Edit:
Here is what the XAML for my UserControl
<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>
Here are some assumptions:
- You have some outer UserControl or Page.
- This outer UserControl contains a Canvas.
- This Canvas in turn has several direct children which are instances of your
Carcassonne.Tile
control. - You have attached an event handler to each tiles Left Mouse Down event in which you would like to bring the tile affected to the top.
The being the case the code you have already used should work:=
Canvas.SetZIndex((Tile)sender, 99);
Except as you click on other tiles they too end up with a 99 Z-Index. What you need is to hold in common the last Zindex value used and then increment and use its value each time the event happens.
This answer probably doesn't help because of all the assumptions one or more of which may be wrong. If you could be more descriptive in your question a better matching answer could be found.
精彩评论