[Situation]
I have a custom item control which I add to a stack panel and after that is freely to move around by dragging.
public partial class CustomItem: UserControl
{
private bool IsDragging { get; set; }
private Point clickPosition;
public CustomItem()
{
InitializeComponent();
this.DataContext = this;
this.MouseLeftButtonDown += (s, ea) =>
{
clickPosition = ea.GetPosition(this.LayoutRoot);
this.CaptureMouse();
IsDragging = true;
};
this.MouseMove += (s, ea) =>
{
if (IsDragging)
{
this.transFormThisShit.X = ea.GetPosition(this).X - clickPosition.X;
this.transFormThisShit.Y = ea.GetPosition(this).Y - clickPosition.Y;
}
};
this.MouseLeftButtonUp += (s, ea) =>
{
this.ReleaseMouseCapture();
IsDragging = false;
};
}
[Problem]
After I add 3 items, and I drag the first item over the second or third, it jumps behind it.
When I drag the second item over the first, it goes in front but when I drag it over the third it goes behind it.
How can I make it so the control dragging is always on top of the visual tree?