Reputation: 2201
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>
Upvotes: 1
Views: 1964
Reputation: 189505
Here are some assumptions:
Carcassonne.Tile
control.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.
Upvotes: 1