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.

  NameDescription
Public methodStatic memberAddDragEnterHandlerAdds a DragEnter event handler to a specified dependency object.
Public methodStatic memberAddDragLeaveHandlerAdds a DragLeave event handler to a specified dependency object.
Public methodStatic memberAddDragOverHandlerAdds a DragOver event handler to a specified dependency object.
Public methodStatic memberAddDropHandlerAdds a Drop event handler to a specified dependency object.
Public methodStatic memberAddGiveFeedbackHandlerAdds a GiveFeedback event handler to a specified dependency object.
Public methodStatic memberAddPreviewDragEnterHandlerAdds a PreviewDragEnter event handler to a specified dependency object.
Public methodStatic memberAddPreviewDragLeaveHandlerAdds a PreviewDragLeave event handler to a specified dependency object.
Public methodStatic memberAddPreviewDragOverHandlerAdds a PreviewDragOver event handler to a specified dependency object.
Public methodStatic memberAddPreviewDropHandlerAdds a PreviewDrop event handler to a specified dependency object.
Public methodStatic memberAddPreviewGiveFeedbackHandlerAdds a PreviewGiveFeedback event handler to a specified dependency object.
Public methodStatic memberAddPreviewQueryContinueDragHandlerAdds a PreviewQueryContinueDrag event handler to a specified dependency object.
Public methodStatic memberAddQueryContinueDragHandlerAdds a QueryContinueDrag event handler to a specified dependency object.
Public methodStatic memberDoDragDropInitiates a drag-and-drop operation.
Public methodStatic memberRemoveDragEnterHandlerRemoves a DragEnter event handler from a specified dependency object.
Public methodStatic memberRemoveDragLeaveHandlerRemoves a DragLeave event handler from a specified dependency object.
Public methodStatic memberRemoveDragOverHandlerRemoves a DragOver event handler from a specified dependency object.
Public methodStatic memberRemoveDropHandlerRemoves a Drop event handler from a specified dependency object.
Public methodStatic memberRemoveGiveFeedbackHandlerRemoves a GiveFeedback event handler from a specified dependency object.
Public methodStatic memberRemovePreviewDragEnterHandlerRemoves a PreviewDragEnter event handler from a specified dependency object.
Public methodStatic memberRemovePreviewDragLeaveHandlerRemoves a PreviewDragLeave event handler from a specified dependency object.
Public methodStatic memberRemovePreviewDragOverHandlerRemoves a PreviewDragOver event handler from a specified dependency object.
Public methodStatic memberRemovePreviewDropHandlerRemoves a PreviewDrop event handler from a specified dependency object.
Public methodStatic memberRemovePreviewGiveFeedbackHandlerRemoves a PreviewGiveFeedback event handler from a specified dependency object.
Public methodStatic memberRemovePreviewQueryContinueDragHandlerRemoves a PreviewQueryContinueDrag event handler from a specified dependency object.
Public methodStatic memberRemoveQueryContinueDragHandlerRemoves a QueryContinueDrag event handler from a specified dependency object.
Top

  NameDescription
Public attached eventDragEnterOccurs when an object is dragged into the bounds of an element.
Public attached eventDragLeaveOccurs when an object is dragged out of the bounds of an element.
Public attached eventDragOverOccurs when an object is dragged over the bounds of an element.
Public attached eventDropOccurs when an object is dropped within the bounds of an element.
Public attached eventGiveFeedbackOccurs when a drag-and-drop operation is started, and enables the drop target to send feedback information to the drop source.
Public attached eventPreviewDragEnterOccurs when an object is dragged into the bounds of an element.
Public attached eventPreviewDragLeaveOccurs when an object is dragged out of the bounds of an element.
Public attached eventPreviewDragOverOccurs when an object is dragged over the bounds of an element.
Public attached eventPreviewDropOccurs when an object is dropped within the bounds of the drop target.
Public attached eventPreviewGiveFeedbackOccurs when a drag-and-drop operation is started, and enables the drop target to send feedback information to the drop source.
Public attached eventPreviewQueryContinueDragOccurs 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 eventQueryContinueDragOccurs 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

  NameDescription
Public fieldStatic memberDragEnterEventIdentifies the DragEnter  attached event.
Public fieldStatic memberDragLeaveEventIdentifies the DragLeave  attached event
Public fieldStatic memberDragOverEventIdentifies the DragOver  attached event
Public fieldStatic memberDropEventIdentifies the Drop  attached event
Public fieldStatic memberGiveFeedbackEventIdentifies the GiveFeedback  attached event
Public fieldStatic memberPreviewDragEnterEventIdentifies the PreviewDragEnter  attached event
Public fieldStatic memberPreviewDragLeaveEventIdentifies the PreviewDragLeave  attached event
Public fieldStatic memberPreviewDragOverEventIdentifies the PreviewDragOver  attached event
Public fieldStatic memberPreviewDropEventIdentifies the PreviewDrop  attached event
Public fieldStatic memberPreviewGiveFeedbackEventIdentifies the PreviewGiveFeedback  attached event
Public fieldStatic memberPreviewQueryContinueDragEventIdentifies the PreviewQueryContinueDrag  attached event
Public fieldStatic memberQueryContinueDragEventIdentifies 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.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft