Reputation: 117
During a drag in Wpf, how can the mouse cursor (or perhaps using an adorner) be changed to indicate that the droptarget
will not accept the dragged item?
I've tried to set e.Effects = DragDropEffects.None
during the DragEnter
event but this isn't working and I suspect that I've misunderstood what that feature should be used for. I've tried using the GiveFeedback
event but don't see how the droptarget
can influence it.
Upvotes: 7
Views: 6528
Reputation: 21
If you want the app to take your change in account, you should set Handled property to true:
private void OnDragOver(object sender, DragEventArgs e)
{
if (your_test)
e.Effects = DragDropEffects.Link;//or other effect you want
else
e.Effects = DragDropEffects.None;
e.Handled = true;
}
Upvotes: 2
Reputation: 1136
You didn't say if you use the DragOver
even. Maybe you're setting e.Effect = DragDropEffects.All;
in this even and it will be fired repeatedly after you enter the target control instead of DragEnter
that will be fired just once.
private void arbol_DragOver(object sender, DragEventArgs e)
{
if (some_reason)
e.Effect = DragDropEffects.None;
else
e.Effect = DragDropEffects.All;
}
If you didn't use this event or didn't modify e.Effect
within, then it's hard to say. Code is needed.
Upvotes: 1
Reputation: 41
I had a similar problem because I changed the cursor in the GiveFeedback handler. This cursor was used even the drop target did reject the data. After switching back to the default cursor (e.UseDefaultCursors = true) the cursor shape did change propely to "not allowed".
Upvotes: 0
Reputation: 4773
Just setting the DragDropEffects in DragEnter of the drop target should work. Is your DragEnter even getting called. Have you set AllowDrop on the drop target control?
This is the sequence of events during a drag & drop in WPF (taken from MSDN) which might help work out what's going on...
Dragging is initiated by calling the DoDragDrop method for the source control.
The DoDragDrop method takes two parameters: * data, specifying the data to pass * allowedEffects, specifying which operations (copying and/or moving) are allowed
A new DataObject object is automatically created.
Upvotes: 8