That information is passed back to the drag source as the return value of the DoDragDrop method. When the data is dropped, the drop target specifies its actual effect in the Drop event. The drag source uses this information to inform the user what effect the drop target intends to have on the data. When the drop target specifies its intended effect in the DragOver event, that information is passed back to the drag source in the GiveFeedback event. In the drop target, you can specify the effect that the target intends in the Effects property of the DragEventArgs class. In the drag source, you can specify the effects that the source will allow in the DoDragDrop method. WPF defines a DragDropEffects enumeration that you can use to specify the effect of a drag-and-drop operation. For example, you can copy the data or you can move the data. Drag-and-Drop Effectsĭrag-and-drop operations can have different effects on the transferred data. By default, feedback is provided to the user by changing the cursor to represent the effect that the drag-and-drop operation will have on the data, such as whether the data will be moved or copied. You can write code to provide a visual representation of the data that is dragged, such as occurs when dragging files in Windows Explorer. The source and target of a drag-and-drop operation are UI elements however, the data that is actually being transferred typically does not have a visual representation. For more information about working with data objects, see Data and Data Objects. The drop target is responsible for extracting the data from the DataObject. For greater control over the data format, you can wrap the data in a DataObject before passing it to the DoDragDrop method. The DoDragDrop method will automatically wrap the data in a DataObject if necessary. The drag source initiates a drag-and-drop operation by calling the static DragDrop.DoDragDrop method and passing the transferred data to it. Conceptually, a data object consists of one or more pairs of an Object that contains the actual data, and a corresponding data format identifier. In a copy-and-paste operation, the system clipboard is used to temporarily store the transferred data in a drag-and-drop operation, a DataObject is used to store the data. Both types of operations require:Ī way to temporarily store the transferred data. A drag-and-drop operation is analogous to a copy-and-paste or cut-and-paste operation that is used to transfer data from one object or application to another by using the system clipboard. Data transfer includes drag-and-drop and copy-and-paste operations. OLE drag-and-drop does not work while in the Internet zone.ĭrag-and-drop is part of the more general area of data transfer. For more information, see the UIElement.Drop event. Event handlers that are attached to these events are attached to the underlying DragDrop attached event and receive the same event data instance. ![]() ![]() The UIElement and ContentElement classes contain aliases for the DragDrop attached events so that the events appear in the class members list when a UIElement or ContentElement is inherited as a base element. The events and methods required for drag-and-drop operations are defined in the DragDrop class. ![]() In WPF, any UIElement or ContentElement can participate in drag-and-drop. Dragging-and-dropping between WPF applications and other Windows applications is also fully supported. Drag-and-drop supports manipulating objects within a single application, or between different applications. The drag-and-drop facilities provided by WPF are designed to be highly flexible and customizable to support a wide variety of drag-and-drop scenarios. For example, dragging a selection of files from one folder to another on the same storage device moves the files by default, whereas dragging files from a Universal Naming Convention (UNC) share to a local folder copies the files by default. ![]() The particular actions performed during a drag-and-drop operation are application specific, and often determined by context. For example, files, folders, and selections of content are some of the more common objects manipulated through drag-and-drop operations. The type and number of objects that can be manipulated with drag-and-drop is completely arbitrary. The drag source and drop target may be UI elements in the same application or a different application. This topic provides an overview of drag-and-drop support in user interface (UI), and dropping them.ĭrag-and-drop operations typically involve two parties: a drag source from which the dragged object originates and a drop target which receives the dropped object.
0 Comments
Leave a Reply. |