Freigeben über


Drag-and-Drop Events Explorer Sample

This sample explores how and when common drag and drop events fire. Events demonstrated in this sample include:

Bubbling Tunneling

DragEnter

PreviewDragEnter

DragLeave

PreviewDragLeave

DragOver

PreviewDragOver

Drop

PreviewDrop

The sample provides a UIElement (which happens to be a TextBlock) that is configured to be the target of a drag-and-drop operation; this drop-target support is enabled by setting the AllowDrop attribute to true on the target element, which can be a UIElement or a ContentElement.

Simple event handlers are attached to the UIElement for each of the drag-and-drop events listed in the table above. Whenever any of these events fires, a log entry is written to a log window included in the sample. The sample supports both brief and verbose event logging.

To observe when and in what order the events fire, drag any object into, over, or out of the bounds of the drop-target area, or drop any object on the drop-target area.

This sample demonstrates a specific feature of the Windows Presentation Foundation (WPF) and, consequently, does not follow application development best practices. For comprehensive coverage of Windows Presentation Foundation (WPF) and Microsoft .NET Framework application development best practices, refer to the following as appropriate:

Accessibility - Accessibility Best Practices

Security - WPF Security

Localization - WPF Globalization and Localization Overview

Download sample

Building the Sample

  • Install the Windows Software Development Kit (SDK) and open its build environment command window. On the Start menu, point to All Programs, Microsoft Windows SDK, and then click CMD Shell.

  • Download the sample, usually from the software development kit (SDK) documentation, to your hard disk drive.

  • To build the sample from the build environment command window, go to the source directory of the sample. At the command prompt, type MSBUILD.

  • To build the sample in Microsoft Visual Studio 2005, load the sample solution or project file and then press CTRL+SHIFT+B.

Running the Sample

  • To run the compiled sample from the build environment command window, execute the .exe file in the Bin\Debug or Bin\Release folder contained under the sample source code folder.

  • To run the compiled sample with debugging in Visual Studio 2005, press F5.

See Also

Reference

IDataObject
DataObject
DataFormats
GetData
GetFormats
GetDataPresent