This topic has not yet been rated - Rate this topic

DragDrop Class

Provides helper methods and fields for initiating drag-and-drop operations, including a method to begin a drag-and-drop operation, and facilities for adding and removing drag-and-drop related event handlers.

System.Object
  System.Windows.DragDrop

Namespace:  System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)
public static class DragDrop

The DragDrop type exposes the following members.

  Name Description
Public method Static member AddDragEnterHandler Adds a DragEnter event handler to a specified dependency object.
Public method Static member AddDragLeaveHandler Adds a DragLeave event handler to a specified dependency object.
Public method Static member AddDragOverHandler Adds a DragOver event handler to a specified dependency object.
Public method Static member AddDropHandler Adds a Drop event handler to a specified dependency object.
Public method Static member AddGiveFeedbackHandler Adds a GiveFeedback event handler to a specified dependency object.
Public method Static member AddPreviewDragEnterHandler Adds a PreviewDragEnter event handler to a specified dependency object.
Public method Static member AddPreviewDragLeaveHandler Adds a PreviewDragLeave event handler to a specified dependency object.
Public method Static member AddPreviewDragOverHandler Adds a PreviewDragOver event handler to a specified dependency object.
Public method Static member AddPreviewDropHandler Adds a PreviewDrop event handler to a specified dependency object.
Public method Static member AddPreviewGiveFeedbackHandler Adds a PreviewGiveFeedback event handler to a specified dependency object.
Public method Static member AddPreviewQueryContinueDragHandler Adds a PreviewQueryContinueDrag event handler to a specified dependency object.
Public method Static member AddQueryContinueDragHandler Adds a QueryContinueDrag event handler to a specified dependency object.
Public method Static member DoDragDrop Initiates a drag-and-drop operation.
Public method Static member RemoveDragEnterHandler Removes a DragEnter event handler from a specified dependency object.
Public method Static member RemoveDragLeaveHandler Removes a DragLeave event handler from a specified dependency object.
Public method Static member RemoveDragOverHandler Removes a DragOver event handler from a specified dependency object.
Public method Static member RemoveDropHandler Removes a Drop event handler from a specified dependency object.
Public method Static member RemoveGiveFeedbackHandler Removes a GiveFeedback event handler from a specified dependency object.
Public method Static member RemovePreviewDragEnterHandler Removes a PreviewDragEnter event handler from a specified dependency object.
Public method Static member RemovePreviewDragLeaveHandler Removes a PreviewDragLeave event handler from a specified dependency object.
Public method Static member RemovePreviewDragOverHandler Removes a PreviewDragOver event handler from a specified dependency object.
Public method Static member RemovePreviewDropHandler Removes a PreviewDrop event handler from a specified dependency object.
Public method Static member RemovePreviewGiveFeedbackHandler Removes a PreviewGiveFeedback event handler from a specified dependency object.
Public method Static member RemovePreviewQueryContinueDragHandler Removes a PreviewQueryContinueDrag event handler from a specified dependency object.
Public method Static member RemoveQueryContinueDragHandler Removes a QueryContinueDrag event handler from a specified dependency object.
Top
  Name Description
Public attached event DragEnter Occurs when an object is dragged into the bounds of an element.
Public attached event DragLeave Occurs when an object is dragged out of the bounds of an element.
Public attached event DragOver Occurs when an object is dragged over the bounds of an element.
Public attached event Drop Occurs when an object is dropped within the bounds of an element.
Public attached event GiveFeedback Occurs when a drag-and-drop operation is started, and enables the drop target to send feedback information to the drop source.
Public attached event PreviewDragEnter Occurs when an object is dragged into the bounds of an element.
Public attached event PreviewDragLeave Occurs when an object is dragged out of the bounds of an element.
Public attached event PreviewDragOver Occurs when an object is dragged over the bounds of an element.
Public attached event PreviewDrop Occurs when an object is dropped within the bounds of the drop target.
Public attached event PreviewGiveFeedback Occurs when a drag-and-drop operation is started, and enables the drop target to send feedback information to the drop source.
Public attached event PreviewQueryContinueDrag Occurs when there is a change in the keyboard or mouse button states during a drag-and-drop operation, and enables the drop source to cancel the drag-and-drop operation depending on the key/button states.
Public attached event QueryContinueDrag Occurs when there is a change in the keyboard or mouse button states during a drag-and-drop operation, and enables the drop source to cancel the drag-and-drop operation depending on the key/button states.
Top
  Name Description
Public field Static member DragEnterEvent Identifies the DragEnter  attached event.
Public field Static member DragLeaveEvent Identifies the DragLeave  attached event
Public field Static member DragOverEvent Identifies the DragOver  attached event
Public field Static member DropEvent Identifies the Drop  attached event
Public field Static member GiveFeedbackEvent Identifies the GiveFeedback  attached event
Public field Static member PreviewDragEnterEvent Identifies the PreviewDragEnter  attached event
Public field Static member PreviewDragLeaveEvent Identifies the PreviewDragLeave  attached event
Public field Static member PreviewDragOverEvent Identifies the PreviewDragOver  attached event
Public field Static member PreviewDropEvent Identifies the PreviewDrop  attached event
Public field Static member PreviewGiveFeedbackEvent Identifies the PreviewGiveFeedback  attached event
Public field Static member PreviewQueryContinueDragEvent Identifies the PreviewQueryContinueDrag  attached event
Public field Static member QueryContinueDragEvent Identifies the QueryContinueDrag  attached event
Top

Drag-and-drop functionality is designed to work both within an application and between applications. Dragging data between Windows Presentation Foundation (WPF) and non-WPF applications is also supported.

The following example demonstrates how to use a DragDrop object.


Private Sub DragStarted()
    m_IsDown = False

    Dim serializedObject As String = m_OriginalElement.OuterXml
    Dim data As DataObject = New DataObject()
    data.SetData(m_MyFormat.Name, serializedObject)
    Dim effects As DragDropEffects = _
        DragDrop.DoDragDrop(MyCanvas, data, DragDropEffects.Copy Or DragDropEffects.Move)
    If effects And DragDropEffects.Move Then
        ' Remove the element.
        m_OriginalElement.ParentNode.RemoveChild(m_OriginalElement)
        m_OriginalElement = Nothing
    End If
End Sub


.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Ejemplo cambio de fondo con Drag Drop
e.Effect = DragDropEffects.All;
            string[] mycadena = (string[])e.Data.GetData(DataFormats.FileDrop);
            this.BackgroundImage = new Bitmap(@mycadena[0]);