I am new in WPF. I am implementing Drag&Drop in a TreeView and my DragOver event handler does not work.
<Style TargetType="TreeViewItem">
<!-- ... -->
<EventSetter Event="DragOver" Handler="item_DragOver" />
</Style>
void item_DragOver(object sender, DragEventArgs e)
{
if (!e.Data.GetDataPresent("someFormat") || e.Source == sender)
e.Effects = DragDropEffects.None;
else if (e.KeyStates == DragDropKeyStates.ControlKey)
e.Effects = DragDropEffects.Copy;
else
e.Effects = DragDropEffects.Move;
e.Handled = true;
}
When the program runs when dragging over some tree items it shows always a "move" drag icon, even if I press the Ctrl key. I suppose some default event handler overrides my e.Effects, but I do not know where I can search for it.
Any Idea?
I found it, to check if ctrl-key is pressed the right way is:
if ((e.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With