If you select some text
inside a text box, you can drag it to another text box. When you release the mouse button, the
text will be moved. The same technique works between applications??”for example, you can
drag some text from a Word document and drop it into a WPF TextBox object, or vice versa.
nNote Don??™t confuse a drag-and-drop operation with the ability to ???drag??? an element around the window.
This feature is a technique that drawing and diagramming tools use to allow you to move content around.
It??™s demonstrated in Chapter 14.
Sometimes, you might want to allow drag-and-drop between elements that don??™t have the
built-in functionality. For example, you might want to allow the user to drag content from a
text box and drop it in a label. Or you might want to create the example shown in Figure 6-8,
which allows a user to drag text from a Label or TextBox object and drop it into a different
label. In this situation, you need to handle the drag-and-drop events.
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 179
Figure 6-8. Dragging content from one element to another
There are two sides to a drag-and-drop operation: the source and target. To create a dragand-
drop source, you need to call the DragDrop.DoDragDrop() method at some point to
initiate the drag-and-drop operation.
Pages:
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354