This documentation is archived and is not being maintained.

DataObject.DataObject(String, Object) Constructor

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
)
public DataObject (
	String format, 
	Object data
)
public function DataObject (
	format : String, 
	data : Object
)
You cannot use constructors in XAML.

Parameters

format

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

data

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

Exception typeCondition

ArgumentNullException

data or format is a null reference (Nothing in Visual Basic).

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...");

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Show: