Implementing Drag and Drop similar
[Situation]
I have a custom userControl (Basicly a iamge with some text beneath it). In my program I add two of these and implement a drag method by
public partial class CustomItem : UserControl
{
private开发者_Python百科 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]
I can freely move around the objects over the screen which is exactly what I want. But when I drop 2 of these controls on top of eachother I wish to have a event happen. Anything at all, but somehow I can't seem to get any reading on the Control that I drop it on.
Is there any possible way to implement this in the above given code so that when I drop 2 of this control on top of eachother I can catch a / some event to which I can get both controls?
Hope you understand my question.
[Edit]
If not possible in current context please hint a way in which I can do it with custom controls..
Maybe there's something like a drag/drop control which I can "edit" into the same as this control is!
In the MouseLeftButtonUp event, you can use check the co-ordinates the control has been dragged to and compare these with the control you wish to drop onto. I can't see any other obvious way to do this.
There are drag and drop frameworks for things like re-ordering items in list boxes, so if you find you're implementing something pretty standard you shouldn't need to re-invent the wheel.
精彩评论