DataObject 构造函数

定义

初始化 DataObject 类的新实例。Initializes a new instance of the DataObject class.

重载

DataObject()

初始化 DataObject 类的新实例。Initializes a new instance of the DataObject class.

DataObject(Object)

初始化包含指定数据的 DataObject 类的新实例。Initializes a new instance of the DataObject class that contains the specified data.

DataObject(String, Object)

初始化 DataObject 类的新实例,该类包含指定数据及其关联格式;格式由字符串指定。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)

初始化 DataObject 类的新实例,该类包含指定数据及其关联格式;数据格式由 Type 对象指定。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)

初始化 DataObject 类的新实例,该类包含指定数据及其关联格式;格式由字符串指定。Initializes a new instance of the DataObject class that contains the specified data and its associated format; the format is specified by a string. 此重载包含一个 Boolean 标志,用于指示是否可在检索时将数据转换为其他格式。This overload includes a Boolean flag to indicate whether the data may be converted to another format on retrieval.

DataObject()

初始化 DataObject 类的新实例。Initializes a new instance of the DataObject class.

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

适用于

DataObject(Object)

初始化包含指定数据的 DataObject 类的新实例。Initializes a new instance of the DataObject class that contains the specified data.

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

参数

data
Object

一个对象,表示要在此数据对象中存储的数据。An object that represents the data to store in this data object.

属性

例外

datanulldata is null.

data 引用 DataObject 对象。data references a DataObject object.

示例

下面的示例创建一个新的数据对象,并使用此构造函数来初始化带有字符串的数据对象。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...")

适用于

DataObject(String, Object)

初始化 DataObject 类的新实例,该类包含指定数据及其关联格式;格式由字符串指定。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);
public DataObject (string format, object data);
[System.Security.SecurityCritical]
public DataObject (string format, object data);
new System.Windows.DataObject : string * obj -> System.Windows.DataObject
[<System.Security.SecurityCritical>]
new System.Windows.DataObject : string * obj -> System.Windows.DataObject
Public Sub New (format As String, data As Object)

参数

format
String

一个指定数据格式的字符串。A string that specifies the format for the data. 有关预定义数据格式集,请参阅 DataFormats 类。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.

属性

例外

dataformatnulldata 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. 在这种情况下,数据格式由字符串指定; DataFormats 类提供一组预定义类型字符串。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...")

适用于

DataObject(Type, Object)

初始化 DataObject 类的新实例,该类包含指定数据及其关联格式;数据格式由 Type 对象指定。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);
public DataObject (Type format, object data);
[System.Security.SecurityCritical]
public DataObject (Type format, object data);
new System.Windows.DataObject : Type * obj -> System.Windows.DataObject
[<System.Security.SecurityCritical>]
new System.Windows.DataObject : Type * obj -> System.Windows.DataObject
Public Sub New (format As Type, data As Object)

参数

format
Type

一个 Type,指定数据的格式。A Type that specifies the format for the data. 有关预定义数据格式集,请参阅 DataFormats 类。For a set of predefined data formats, see the DataFormats class.

data
Object

要在此数据对象中存储的数据。The data to store in this data object.

属性

例外

dataformatnulldata 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. 在这种情况下,数据格式是由参数指定的 TypeIn 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...")

适用于

DataObject(String, Object, Boolean)

初始化 DataObject 类的新实例,该类包含指定数据及其关联格式;格式由字符串指定。Initializes a new instance of the DataObject class that contains the specified data and its associated format; the format is specified by a string. 此重载包含一个 Boolean 标志,用于指示是否可在检索时将数据转换为其他格式。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);
public DataObject (string format, object data, bool autoConvert);
[System.Security.SecurityCritical]
public DataObject (string format, object data, bool autoConvert);
new System.Windows.DataObject : string * obj * bool -> System.Windows.DataObject
[<System.Security.SecurityCritical>]
new System.Windows.DataObject : string * obj * bool -> System.Windows.DataObject
Public Sub New (format As String, data As Object, autoConvert As Boolean)

参数

format
String

一个指定数据格式的字符串。A string that specifies the format for the data. 有关预定义数据格式集,请参阅 DataFormats 类。For a set of predefined data formats, see the DataFormats class.

data
Object

要在此数据对象中存储的数据。The data to store in this data object.

autoConvert
Boolean

如果允许在检索时将数据转换为其他格式,则为 true;如果禁止在检索时将数据转换为其他格式,则为 falsetrue 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.

属性

例外

dataformatnulldata 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. 在这种情况下,数据格式由字符串指定; DataFormats 类提供一组预定义类型字符串。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)

适用于