How can I, in WPF, create an ability to drag a marker onto another window? If I can use the standard drag and drop, then I need a way to handle an event when the drag is completed. (No actual data will be copied, the drag and drop would actually fail in terms of standard usage, but at the ending point I would use a library to record the mouse's position and other information, which is all I need.) If that isn't possible, then how can I intercept mouse events once the mouse has left the window to know when the user has released the button?
In .NET you know when the user has released the mouse because you have assigned a delegate to the Control's DragDrop event.
Okay, I've made a WPF window and I've placed several types of controls on it. None of them have a DragDrop event. That only seems to apply to controls in the System.Windows.Forms namespace. Is there an equivalent for WPF?
Well, it's not at all intuitive, but I think I've found a way to make it work:
public partial class Window1 : Window
this.ellipse1.MouseDown += new MouseButtonEventHandler(ellipse1_MouseDown);
this.ellipse1.QueryContinueDrag += new QueryContinueDragEventHandler(ellipse1_QueryContinueDrag);
void ellipse1_MouseDown(object sender, MouseEventArgs e)
DataObject data = new DataObject();
void ellipse1_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
if ((e.KeyStates & DragDropKeyStates.LeftMouseButton) != DragDropKeyStates.LeftMouseButton)
// This will happen at the end of the drag
You'll have to be careful to anticipate other things like mouse clicks (which would also trigger MouseDown), right-drags, and other such things. This is a lot less clean than the DragDrop event, but I guess it gets the job done.