-
February 12th, 2010, 05:22 PM
#1
Creating a drag & drop system
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?
-
February 12th, 2010, 05:45 PM
#2
Re: Creating a drag & drop system
In .NET you know when the user has released the mouse because you have assigned a delegate to the Control's DragDrop event.
-
February 12th, 2010, 05:54 PM
#3
Re: Creating a drag & drop system
Originally Posted by BigEd781
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?
-
February 12th, 2010, 06:35 PM
#4
Re: Creating a drag & drop system
Ahhh, I was unsure if that would be the case. I do not know WPF, but here is an article:
http://msdn.microsoft.com/en-us/library/ms742859.aspx
-
February 12th, 2010, 08:41 PM
#5
Re: Creating a drag & drop system
Well, it's not at all intuitive, but I think I've found a way to make it work:
Code:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
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();
DragDrop.DoDragDrop(
this.ellipse1,
data,
DragDropEffects.All);
}
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|