#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);
        }


About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: