Apparently Grid.SetZIndex() doesn't exist . As doesn't ctrl.SetValue(Grid.ZIndexProperty…).
So how do I bring a Child of Grid
to Front?
Apparently Grid.SetZIndex() doesn't exist . As doesn't ctrl.SetValue(Grid.ZIndexProperty…).
So how do I bring a Child of Grid
to Front?
ZIndex
is only valid inside a Canvas
control.
<Canvas>
<Grid Canvas.ZIndex="0"/>
<Grid Canvas.ZIndex="1"/>
</Canvas>
Otherwise, such as in a grid
, the placement in the document outline determines the z index. That is to say, the later it is in your XAML page the higher it is in the Z index.
Best of luck!
In this case you can find your UIElement in Children and move it on top:
// Type of parent element could be any your control
public static void MoveUiOnTop(UIElement element, Grid yourParentElement)
{
int index = yourParentElement.Children.IndexOf(element);
if (index != -1)
yourParentElement.Children.Move((uint)index, (uint)yourParentElement.Children.Count - 1);
}
This example written "on the knee" but I use this small trick from time to time. Or you can try to create extension like this:
public static void MoveUiOnTop(this UIElement element, T yourParentElement)
but be careful with type of parent element or do not use generic.