#710 – DoDragDrop Is a Blocking Call

When you initiate a drag-and-drop operation by callingĀ DragDrop.DoDragDrop, control will not return from theĀ DoDragDrop method until the drag-and-drop operation has completed.

        private void Label_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DataObject data = new DataObject(DataFormats.Text, ((Label)e.Source).Content);

            DragDrop.DoDragDrop((DependencyObject)e.Source, data, DragDropEffects.Copy);

            // Not called until drag-and-drop is done
            ((Label)e.Source).Content = "DragDrop done";
        }

        private void Label_Drop(object sender, DragEventArgs e)
        {
            ((Label)e.Source).Content = (string)e.Data.GetData(DataFormats.Text);
        }

710-001
710-002

Advertisement