संपादित करें

इसके माध्यम से साझा किया गया


DataObject Constructors

Definition

Initializes a new instance of the DataObject class.

Overloads

DataObject()

Initializes a new instance of the DataObject class.

DataObject(Object)

Initializes a new instance of the DataObject class that contains the specified data.

DataObject(String, Object)

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

DataObject(Type, Object)

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

DataObject(String, Object, Boolean)

Initializes a new instance of the DataObject class that contains the specified data and its associated format; the format is specified by a string. This overload includes a Boolean flag to indicate whether the data may be converted to another format on retrieval.

DataObject()

Initializes a new instance of the DataObject class.

public:
 DataObject();
[System.Security.SecurityCritical]
public DataObject ();
public DataObject ();
Public Sub New ()
Attributes

Applies to

DataObject(Object)

Initializes a new instance of the DataObject class that contains the specified data.

public:
 DataObject(System::Object ^ data);
[System.Security.SecurityCritical]
public DataObject (object data);
public DataObject (object data);
[<System.Security.SecurityCritical>]
new System.Windows.DataObject : obj -> System.Windows.DataObject
new System.Windows.DataObject : obj -> System.Windows.DataObject
Public Sub New (data As Object)

Parameters

data
Object

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

Attributes

Exceptions

data is null.

data references a DataObject object.

Examples

The following example creates a new data object and uses this constructor 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.

string stringData = "Some string data to store...";
DataObject dataObject = new DataObject(stringData);
Dim stringData As String = "Some string data to store..."
Dim dataObject As New DataObject(stringData)

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

DataObject dataObject = new DataObject("Some string data to store...");
Dim dataObject As New DataObject("Some string data to store...")

Applies to

DataObject(String, Object)

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

public:
 DataObject(System::String ^ format, System::Object ^ data);
[System.Security.SecurityCritical]
public DataObject (string format, object data);
public DataObject (string format, object data);
[<System.Security.SecurityCritical>]
new System.Windows.DataObject : string * obj -> System.Windows.DataObject
new System.Windows.DataObject : string * obj -> System.Windows.DataObject
Public Sub New (format As String, data As Object)

Parameters

format
String

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

data
Object

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

Attributes

Exceptions

data or format is null.

Examples

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);
Dim stringData As String = "Some string data to store..."
Dim dataFormat As String = DataFormats.UnicodeText
Dim dataObject As 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...");
Dim dataObject As New DataObject(DataFormats.UnicodeText, "Some string data to store...")

Applies to

DataObject(Type, Object)

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

public:
 DataObject(Type ^ format, System::Object ^ data);
[System.Security.SecurityCritical]
public DataObject (Type format, object data);
public DataObject (Type format, object data);
[<System.Security.SecurityCritical>]
new System.Windows.DataObject : Type * obj -> System.Windows.DataObject
new System.Windows.DataObject : Type * obj -> System.Windows.DataObject
Public Sub New (format As Type, data As Object)

Parameters

format
Type

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

data
Object

The data to store in this data object.

Attributes

Exceptions

data or format is null.

Examples

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 Type parameter. Auto-converting of the stored data is allowed by default.

string stringData = "Some string data to store...";
Type dataFormat = stringData.GetType();
DataObject dataObject = new DataObject(dataFormat, stringData);
Dim stringData As String = "Some string data to store..."
Dim dataFormat As Type = stringData.GetType()
Dim dataObject As New DataObject(dataFormat, stringData)

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

DataObject dataObject = new DataObject("".GetType(), "Some string data to store...");
Dim dataObject As New DataObject("".GetType(), "Some string data to store...")

Applies to

DataObject(String, Object, Boolean)

Initializes a new instance of the DataObject class that contains the specified data and its associated format; the format is specified by a string. This overload includes a Boolean flag to indicate whether the data may be converted to another format on retrieval.

public:
 DataObject(System::String ^ format, System::Object ^ data, bool autoConvert);
[System.Security.SecurityCritical]
public DataObject (string format, object data, bool autoConvert);
public DataObject (string format, object data, bool autoConvert);
[<System.Security.SecurityCritical>]
new System.Windows.DataObject : string * obj * bool -> System.Windows.DataObject
new System.Windows.DataObject : string * obj * bool -> System.Windows.DataObject
Public Sub New (format As String, data As Object, autoConvert As Boolean)

Parameters

format
String

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

data
Object

The data to store in this data object.

autoConvert
Boolean

true to allow the data to be converted to another format on retrieval; false to prohibit the data from being converted to another format on retrieval.

Attributes

Exceptions

data or format is null.

Examples

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.

string stringData = "Some string data to store...";
string dataFormat = DataFormats.Text;
bool autoConvert = false;
DataObject dataObject = new DataObject(dataFormat, stringData, autoConvert);
Dim stringData As String = "Some string data to store..."
Dim dataFormat As String = DataFormats.Text
Dim autoConvert As Boolean = False
Dim dataObject As New DataObject(dataFormat, stringData, autoConvert)

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

DataObject dataObject = new DataObject(DataFormats.Text, "Some string data to store...", false);
Dim dataObject As New DataObject(DataFormats.Text, "Some string data to store...", False)

Applies to