Files
Pooja PoojariandAndy De George caa62283b8 US-1889327: Suggestion/warning fixes for WPF. (#1314)
* Suggestion/warning fixes for US-1889327.

* Updated H2s.

* Minor content edit.

* Review edits.

* Minor edits.

* Update dotnet-desktop-guide/framework/wpf/advanced/localization-attributes-and-comments.md

Co-authored-by: Andy (Steve) De George <[email protected]>
2022-02-23 10:27:19 -08:00

6.4 KiB

title, ms.date, ms.custom, description, dev_langs, helpviewer_keywords, ms.assetid
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.
csharp
vb
DataObject class [WPF], creating
data objects [WPF], creating
drag-and-drop [WPF], creating data objects
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.

DataObject(Object) constructor

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]

DataObject(String, Object) constructor

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]

DataObject() constructor

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]

DataObject(String, Object, Boolean) constructor

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]

See also