title | ms.date | ms.custom | description | dev_langs | helpviewer_keywords | ms.assetid | |||||
---|---|---|---|---|---|---|---|---|---|---|---|
How to: Create a Data Object |
03/30/2017 |
devdivchpfy22 |
Learn how to create a Data Object. |
|
|
022fa142-717d-4fea-a53c-3b52e9d91aff |
The following examples show various ways to create a data object using the constructors provided by the xref:System.Windows.DataObject class.
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-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Simple] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Simple]
The following example code is a condensed version of the code shown above.
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Simple_Condensed] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Simple_Condensed]
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-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_TypeString] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_TypeString]
The following example code is a condensed version of the code shown above.
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_TypeString_Condensed] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_TypeString_Condensed]
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-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Type] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Type]
The following example code is a condensed version of the code shown above.
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Type_Condensed] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_Type_Condensed]
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-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_AutoConvert] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_AutoConvert]
The following example code is a condensed version of the code shown above.
[!code-csharpDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_AutoConvert_Condensed] [!code-vbDragDrop_DragDropMiscCode#_DragDrop_CreateDataObject_AutoConvert_Condensed]
- xref:System.Windows.IDataObject