* Reset branch for WPF changes * Convert BMP to PNG; fix link-out-of-scope err * Add snippets for WPF... 6794 files!!!! * Add missing snippets * update file updated between migration * Fix paths to include * update breadcrumb and toc * fix index links * fix index links * fix index links * fix markdown
6.3 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||
|---|---|---|---|---|---|---|---|---|---|
| How to: Create a Data Object | 03/30/2017 |
|
|
022fa142-717d-4fea-a53c-3b52e9d91aff |
How to: Create a Data Object
The following examples show various ways to create a data object using the constructors provided by the xref:System.Windows.DataObject class.
Example
Description
The following example code creates a new data object and uses one of the overloaded constructors (xref:System.Windows.DataObject.%23ctor%28System.Object%29) to initialize the data object with a string. In this case, an appropriate data format is determined automatically according to the stored data's type, and auto-converting of the stored data is allowed by default.
Code
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Simple] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Simple]
Description
The following example code is a condensed version of the code shown above.
Code
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Simple_Condensed] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Simple_Condensed]
Example
Description
The following example code creates a new data object and uses one of the overloaded constructors (xref:System.Windows.DataObject.%23ctor%28System.String%2CSystem.Object%29) to initialize the data object with a string and a specified data format. In this case the data format is specified by a string; the xref:System.Windows.DataFormats class provides a set of pre-defined type strings. Auto-converting of the stored data is allowed by default.
Code
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_TypeString] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_TypeString]
Description
The following example code is a condensed version of the code shown above.
Code
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_TypeString_Condensed] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_TypeString_Condensed]
Example
Description
The following example code creates a new data object and uses one of the overloaded constructors (xref:System.Windows.DataObject.%23ctor%2A) to initialize the data object with a string and a specified data format. In this case the data format is specified by a xref:System.Type parameter. Auto-converting of the stored data is allowed by default.
Code
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Type] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Type]
Description
The following example code is a condensed version of the code shown above.
Code
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Type_Condensed] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Type_Condensed]
Example
Description
The following example code creates a new data object and uses one of the overloaded constructors (xref:System.Windows.DataObject.%23ctor%28System.String%2CSystem.Object%2CSystem.Boolean%29) to initialize the data object with a string and a specified data format. In this case the data format is specified by a string; the xref:System.Windows.DataFormats class provides a set of pre-defined type strings. This particular constructor overload enables the caller to specify whether auto-converting is allowed.
Code
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_AutoConvert] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_AutoConvert]
Description
The following example code is a condensed version of the code shown above.
Code
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_AutoConvert_Condensed] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_AutoConvert_Condensed]