DataObject Constructor (String, Object)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Initializes a new instance of the DataObject class that contains the specified data and its associated format; the format is specified by a string.

Namespace:   System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)

public DataObject(
	string format,
	object data


Type: System.String

A string that specifies the format for the data. For a set of predefined data formats, see the DataFormats class.

Type: System.Object

An object that represents the data to store in this data object.

Exception Condition

data or format is null.

The following example creates a new data object and uses this constructor 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 DataFormats class provides a set of predefined type strings. Auto-converting of the stored data is allowed by default.

string stringData = "Some string data to store...";
string dataFormat = DataFormats.UnicodeText;
DataObject dataObject = new DataObject(dataFormat, stringData);

The following example is a condensed version of the previous example.

DataObject dataObject = new DataObject(DataFormats.UnicodeText, "Some string data to store...");

.NET Framework
Available since 3.0
Return to top