Prev | Current Page 344 | Next

Matthew MacDonald

"Pro WPF with VB 2008: Windows Presentation Foundation with .NET 3.5"

Data.GetDataPresent(DataFormats.Text) Then
e.Effects = DragDropEffects.Copy
Else
e.Effects = DragDropEffects.None
End If
End Sub
CHAPTER 6 n DEPENDENCY PROPERTIES AND ROUTED EVENTS 180
Finally, when the operation completes you can retrieve the data and act on it. The following
code takes the dropped text and inserts it into the label:
Private Sub lblTarget_Drop(ByVal sender As Object, ByVal e As DragEventArgs)
CType(sender, Label).Content = e.Data.GetData(DataFormats.Text)
End Sub
You can exchange any type of object through a drag-and-drop operation. However, while
this free-spirited approach is perfect for your applications, it isn??™t wise if you need to communicate
with other applications. If you want to drag-and-drop into other applications, you
should use a basic data type (such as string, int, and so on), or an object that implements
ISerializable or IDataObject (which allows .NET to transfer your object into a stream of bytes
and reconstruct the object in another application domain). One interesting trick is to convert
a WPF element into XAML and reconstitute it somewhere else. All you need is the XamlWriter
and XamlReader objects described in Chapter 2.
nNote If you want to transfer data between applications, be sure to check out the System.Windows.Clipboard
class, which provides shared methods for placing data on the Windows clipboard and retrieving
it in a variety of different formats.


Pages:
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356