#697 – Dragging Data Out of Your Application

When you use a user interface element as a drag-and-drop source, you initiate the drag-and-drop operation by calling the DragDrop.DoDragDrop method.  The data that you specify when calling this method can then be dragged onto other elements in your application that act as drop targets.   You can also drag data out to another application that knows how to act as a drag-and-drop target.

In the example below, we left-click and drag on the Image, then dropping data into Microsoft Word.  The actual data dropped is textual.

        private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            string textToDrag = "On November 23, 1936, the first issue of the pictorial magazine Life is published, featuring a cover photo of the Fort Peck Dam by Margaret Bourke-White.";

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