Implementing drag-and-drop
Drag-and-drop functionality is common in applications, where one object is held down and dragged to some other object with the mouse. This approach is not as common as it used to be, especially with a mouse, because it requires hand coordination skills. Recent tablet devices are touch enabled, where drag and drop makes a lot of sense. As a general rule, always provide an alternative to drag-and-drop. That said, this can be a handy feature for advanced users.
Getting ready
Make sure Visual Studio is up and running.
How to do it...
We'll create an application that allows dragging elements (circles and rectangles) from one part of the window to another container within the same window, showing the necessary steps to get drag-and-drop working properly:
Create a new WPF application named
CH03.SimpleDragDrop
.Open
MainWindow.xaml
. Fill the existingGrid
with the following markup:<Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="2*"/> ...