DataObject DataObject DataObject DataObject Class

定义

提供 IDataObject 接口的基本实现,该接口为传输数据定义与格式无关的机制。Provides a basic implementation of the IDataObject interface, which defines a format-independent mechanism for transferring data.

public ref class DataObject sealed : System::Runtime::InteropServices::ComTypes::IDataObject, System::Windows::IDataObject
public sealed class DataObject : System.Runtime.InteropServices.ComTypes.IDataObject, System.Windows.IDataObject
type DataObject = class
    interface IDataObject
    interface IDataObject
Public NotInheritable Class DataObject
Implements IDataObject, IDataObject
继承
DataObjectDataObjectDataObjectDataObject
实现

示例

下面的示例演示如何使用此类。The following example shows how to use this class.

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)

注解

重要

使用不受信任的数据调用此类中的方法存在安全风险。Calling methods from this class with untrusted data is a security risk. 仅使用受信任的数据调用此类中的方法。Call the methods from this class only with trusted data. 有关详细信息,请参阅数据验证For more information, see Data Validation.

构造函数

DataObject() DataObject() DataObject() DataObject()

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

DataObject(Object) DataObject(Object) DataObject(Object) DataObject(Object)

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

DataObject(String, Object) DataObject(String, Object) DataObject(String, Object) 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(String, Object, Boolean) DataObject(String, Object, Boolean) DataObject(String, Object, Boolean) 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(Type, Object) DataObject(Type, Object) DataObject(Type, Object) 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.

字段

CopyingEvent CopyingEvent CopyingEvent CopyingEvent

标识 Copying 附加事件。Identifies the Copying attached event.

PastingEvent PastingEvent PastingEvent PastingEvent

标识 Pasting 附加事件。Identifies the Pasting attached event.

SettingDataEvent SettingDataEvent SettingDataEvent SettingDataEvent

标识 SettingData 附加事件。Identifies the SettingData attached event.

方法

AddCopyingHandler(DependencyObject, DataObjectCopyingEventHandler) AddCopyingHandler(DependencyObject, DataObjectCopyingEventHandler) AddCopyingHandler(DependencyObject, DataObjectCopyingEventHandler) AddCopyingHandler(DependencyObject, DataObjectCopyingEventHandler)

Copying 事件处理程序添加到指定的依赖对象。Adds a Copying event handler to a specified dependency object.

AddPastingHandler(DependencyObject, DataObjectPastingEventHandler) AddPastingHandler(DependencyObject, DataObjectPastingEventHandler) AddPastingHandler(DependencyObject, DataObjectPastingEventHandler) AddPastingHandler(DependencyObject, DataObjectPastingEventHandler)

Pasting 事件处理程序添加到指定的依赖对象。Adds a Pasting event handler to a specified dependency object.

AddSettingDataHandler(DependencyObject, DataObjectSettingDataEventHandler) AddSettingDataHandler(DependencyObject, DataObjectSettingDataEventHandler) AddSettingDataHandler(DependencyObject, DataObjectSettingDataEventHandler) AddSettingDataHandler(DependencyObject, DataObjectSettingDataEventHandler)

SettingData 事件处理程序添加到指定的依赖对象。Adds a SettingData event handler to a specified dependency object.

ContainsAudio() ContainsAudio() ContainsAudio() ContainsAudio()

查询某数据对象中是否存在 WaveAudio 数据格式的数据。Queries a data object for the presence of data in the WaveAudio data format.

ContainsFileDropList() ContainsFileDropList() ContainsFileDropList() ContainsFileDropList()

查询某数据对象中是否存在 FileDrop 数据格式的数据。Queries a data object for the presence of data in the FileDrop data format.

ContainsImage() ContainsImage() ContainsImage() ContainsImage()

查询某数据对象中是否存在 Bitmap 数据格式的数据。Queries a data object for the presence of data in the Bitmap data format.

ContainsText() ContainsText() ContainsText() ContainsText()

查询某数据对象中是否存在 UnicodeText 格式的数据。Queries a data object for the presence of data in the UnicodeText format.

ContainsText(TextDataFormat) ContainsText(TextDataFormat) ContainsText(TextDataFormat) ContainsText(TextDataFormat)

查询某数据对象中是否存在文本数据格式的数据。Queries a data object for the presence of data in a text data format.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetAudioStream() GetAudioStream() GetAudioStream() GetAudioStream()

返回一个流,其中包含 WaveAudio 数据格式的数据。Returns a stream that contains data in the WaveAudio data format.

GetData(String) GetData(String) GetData(String) GetData(String)

返回指定格式的数据,此格式由字符串指定。Returns data in a format specified by a string.

GetData(String, Boolean) GetData(String, Boolean) GetData(String, Boolean) GetData(String, Boolean)

返回指定格式的数据对象,可选择将数据转换为指定格式。Returns a data object in a specified format, optionally converting the data to the specified format.

GetData(Type) GetData(Type) GetData(Type) GetData(Type)

返回指定格式的数据对象,此格式由 Type 对象指定。Returns a data object in a format specified by a Type object.

GetDataPresent(String) GetDataPresent(String) GetDataPresent(String) GetDataPresent(String)

确定是否具有字符串指定格式的数据,或者数据是否可以转换为字符串指定格式。Determines whether the data is available in, or can be converted to, a format specified by a string.

GetDataPresent(String, Boolean) GetDataPresent(String, Boolean) GetDataPresent(String, Boolean) GetDataPresent(String, Boolean)

确定是否具有指定格式的数据,或者数据是否可以转换为指定格式。Determines whether the data is available in, or can be converted to, a specified format. Boolean 标志,指示当数据不具有指定格式时,是否检查能否将数据转换为此格式。A Boolean flag indicates whether to check if the data can be converted to the specified format if it is not available in that format.

GetDataPresent(Type) GetDataPresent(Type) GetDataPresent(Type) GetDataPresent(Type)

确定是否具有指定格式的数据,或者数据是否可以转换为指定格式,此格式由 Type 对象指定。Determines whether the data is available in, or can be converted to, a format specified by a Type object.

GetFileDropList() GetFileDropList() GetFileDropList() GetFileDropList()

返回包含拖放文件列表的字符串集合。Returns a string collection that contains a list of dropped files.

GetFormats() GetFormats() GetFormats() GetFormats()

返回一个格式列表,此数据对象中的数据以这些格式存储,或可以转换为这些格式。Returns a list of formats in which the data in this data object is stored, or can be converted to.

GetFormats(Boolean) GetFormats(Boolean) GetFormats(Boolean) GetFormats(Boolean)

返回一个格式列表,此数据对象中的数据以这些格式存储。Returns a list of formats in which the data in this data object is stored. Boolean 标志指示是否亦包含可将数据自动转换为的格式。A Boolean flag indicates whether to also include formats that the data can be automatically converted to.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetImage() GetImage() GetImage() GetImage()

返回一个 BitmapSource 对象,其中包含 Bitmap 格式的数据。Returns a BitmapSource object that contains data in the Bitmap format.

GetText() GetText() GetText() GetText()

返回一个字符串,其中包含此数据对象中的 UnicodeText 数据。Returns a string that contains the UnicodeText data in this data object.

GetText(TextDataFormat) GetText(TextDataFormat) GetText(TextDataFormat) GetText(TextDataFormat)

返回一个字符串,其中包含此数据对象中指定格式的文本数据。Returns a string that contains text data of the specified format in this data object.

GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
RemoveCopyingHandler(DependencyObject, DataObjectCopyingEventHandler) RemoveCopyingHandler(DependencyObject, DataObjectCopyingEventHandler) RemoveCopyingHandler(DependencyObject, DataObjectCopyingEventHandler) RemoveCopyingHandler(DependencyObject, DataObjectCopyingEventHandler)

从指定的依赖对象中删除 Copying 事件处理程序。Removes a Copying event handler from a specified dependency object.

RemovePastingHandler(DependencyObject, DataObjectPastingEventHandler) RemovePastingHandler(DependencyObject, DataObjectPastingEventHandler) RemovePastingHandler(DependencyObject, DataObjectPastingEventHandler) RemovePastingHandler(DependencyObject, DataObjectPastingEventHandler)

从指定的依赖对象中删除 Pasting 事件处理程序。Removes a Pasting event handler from a specified dependency object.

RemoveSettingDataHandler(DependencyObject, DataObjectSettingDataEventHandler) RemoveSettingDataHandler(DependencyObject, DataObjectSettingDataEventHandler) RemoveSettingDataHandler(DependencyObject, DataObjectSettingDataEventHandler) RemoveSettingDataHandler(DependencyObject, DataObjectSettingDataEventHandler)

从指定的依赖对象中删除 SettingData 事件处理程序。Removes a SettingData event handler from a specified dependency object.

SetAudio(Byte[]) SetAudio(Byte[]) SetAudio(Byte[]) SetAudio(Byte[])

将音频数据(WaveAudio 数据格式)存储在此数据对象中。Stores audio data (WaveAudio data format) in this data object. 音频数据指定为字节数组。The audio data is specified as a byte array.

SetAudio(Stream) SetAudio(Stream) SetAudio(Stream) SetAudio(Stream)

将音频数据(WaveAudio 数据格式)存储在此数据对象中。Stores audio data (WaveAudio data format) in this data object. 音频数据指定为流。The audio data is specified as a stream.

SetData(Object) SetData(Object) SetData(Object) SetData(Object)

在此数据对象中存储指定的数据,根据源对象类型自动确定数据格式。Stores the specified data in this data object, automatically determining the data format from the source object type.

SetData(String, Object) SetData(String, Object) SetData(String, Object) SetData(String, Object)

在此数据对象中存储指定的数据,以及一种或多种指定的数据格式;数据格式由字符串指定。Stores the specified data in this data object, along with one or more specified data formats; the data format is specified by a string.

SetData(String, Object, Boolean) SetData(String, Object, Boolean) SetData(String, Object, Boolean) SetData(String, Object, Boolean)

在此数据对象中存储指定的数据,以及一种或多种指定的数据格式。Stores the specified data in this data object, along with one or more specified data formats. 此重载包含一个 Boolean 标志,用于指示是否可在检索时将数据转换为其他格式。This overload includes a Boolean flag to indicate whether the data can be converted to another format on retrieval.

SetData(Type, Object) SetData(Type, Object) SetData(Type, Object) SetData(Type, Object)

在此数据对象中存储指定的数据,以及一种或多种指定的数据格式;数据格式由 Type 对象指定。Stores the specified data in this data object, along with one or more specified data formats; the data format is specified by a Type object.

SetFileDropList(StringCollection) SetFileDropList(StringCollection) SetFileDropList(StringCollection) SetFileDropList(StringCollection)

在此数据对象中存储 FileDrop 数据。Stores FileDrop data in this data object. 拖放文件列表指定为字符串集合。The dropped file list is specified as a string collection.

SetImage(BitmapSource) SetImage(BitmapSource) SetImage(BitmapSource) SetImage(BitmapSource)

在此数据对象中存储 Bitmap 数据。Stores Bitmap data in this data object. 图像数据指定为 BitmapSourceThe image data is specified as a BitmapSource.

SetText(String) SetText(String) SetText(String) SetText(String)

在此数据对象中存储指定为字符串的 UnicodeText 数据。Stores UnicodeText data, specified as a string, in this data object.

SetText(String, TextDataFormat) SetText(String, TextDataFormat) SetText(String, TextDataFormat) SetText(String, TextDataFormat)

在此数据对象中存储文本数据。Stores text data in this data object. 使用 TextDataFormat 的成员指定要存储的文本数据的格式。The format of the text data to store is specified with a member of TextDataFormat.

ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

附加事件

Copying Copying Copying Copying

在以下情况下发生:关联的依赖对象已准备好表示复制选定内容的相应数据格式,已将复制选定内容格式添加到 DataObject 中,且准备将 DataObject 置于 Clipboard 上或开始拖放操作。Occurs when the associated dependency object has prepared appropriate data formats that represent the copy selection, added the copy selection formats to a DataObject, and is ready to either place the DataObject on the Clipboard or begin a drag-and-drop operation.

Pasting Pasting Pasting Pasting

当关联的依赖项对象准备粘贴数据时发生。Occurs when the associated dependency object is ready to paste data.

SettingData SettingData SettingData SettingData

当关联的依赖项对象尝试将新的数据格式添加到 DataObject 中时发生。Occurs when the associated dependency object attempts to add a new data format to a DataObject.

显式界面实现

IDataObject.DAdvise(FORMATETC, ADVF, IAdviseSink, Int32) IDataObject.DAdvise(FORMATETC, ADVF, IAdviseSink, Int32) IDataObject.DAdvise(FORMATETC, ADVF, IAdviseSink, Int32) IDataObject.DAdvise(FORMATETC, ADVF, IAdviseSink, Int32)

在数据对象和通知接收器之间创建连接。Creates a connection between a data object and an advisory sink. 此方法由对象进行调用,该对象支持通知接收器并使通知接收器能收到有关对象数据中的更改的通知。This method is called by an object that supports an advisory sink and enables the advisory sink to be notified of changes in the object's data.

IDataObject.DUnadvise(Int32) IDataObject.DUnadvise(Int32) IDataObject.DUnadvise(Int32) IDataObject.DUnadvise(Int32)

销毁以前建立的通知连接。Destroys a notification connection that had been previously established.

IDataObject.EnumDAdvise(IEnumSTATDATA) IDataObject.EnumDAdvise(IEnumSTATDATA) IDataObject.EnumDAdvise(IEnumSTATDATA) IDataObject.EnumDAdvise(IEnumSTATDATA)

创建可用于对当前的通知连接进行枚举的对象。Creates an object that can be used to enumerate the current advisory connections.

IDataObject.EnumFormatEtc(DATADIR) IDataObject.EnumFormatEtc(DATADIR) IDataObject.EnumFormatEtc(DATADIR) IDataObject.EnumFormatEtc(DATADIR)

创建一个用于枚举数据对象的 FORMATETC 结构的对象。Creates an object for enumerating the FORMATETC structures for a data object. 这些结构用于对 GetData(FORMATETC, STGMEDIUM)SetData(FORMATETC, STGMEDIUM, Boolean) 的调用中。These structures are used in calls to GetData(FORMATETC, STGMEDIUM) or SetData(FORMATETC, STGMEDIUM, Boolean).

IDataObject.GetCanonicalFormatEtc(FORMATETC, FORMATETC) IDataObject.GetCanonicalFormatEtc(FORMATETC, FORMATETC) IDataObject.GetCanonicalFormatEtc(FORMATETC, FORMATETC) IDataObject.GetCanonicalFormatEtc(FORMATETC, FORMATETC)

提供一个在逻辑上与更复杂的结构等效的标准 FORMATETC 结构。Provides a standard FORMATETC structure that is logically equivalent to a more complex structure. 使用此方法可以确定两个不同的 FORMATETC 结构是否将返回相同的数据,从而无需重复呈现。Use this method to determine whether two different FORMATETC structures would return the same data, removing the need for duplicate rendering.

IDataObject.GetData(FORMATETC, STGMEDIUM) IDataObject.GetData(FORMATETC, STGMEDIUM) IDataObject.GetData(FORMATETC, STGMEDIUM) IDataObject.GetData(FORMATETC, STGMEDIUM)

从源数据对象中获取数据。Obtains data from a source data object. 数据使用者调用的 GetData(FORMATETC, STGMEDIUM) 方法将呈现指定的 FORMATETC 结构中描述的数据,并通过指定的 STGMEDIUM 结构传输该数据。The GetData(FORMATETC, STGMEDIUM) method, which is called by a data consumer, renders the data described in the specified FORMATETC structure and transfers it through the specified STGMEDIUM structure. 然后,调用方对释放 STGMEDIUM 结构的责任进行假定。The caller then assumes responsibility for releasing the STGMEDIUM structure.

IDataObject.GetDataHere(FORMATETC, STGMEDIUM) IDataObject.GetDataHere(FORMATETC, STGMEDIUM) IDataObject.GetDataHere(FORMATETC, STGMEDIUM) IDataObject.GetDataHere(FORMATETC, STGMEDIUM)

从源数据对象中获取数据。Obtains data from a source data object. 数据使用者调用的此方法与 GetData(FORMATETC, STGMEDIUM) 方法的区别在于调用方必须分配并释放指定的存储介质。This method, which is called by a data consumer, differs from the GetData(FORMATETC, STGMEDIUM) method in that the caller must allocate and free the specified storage medium.

IDataObject.QueryGetData(FORMATETC) IDataObject.QueryGetData(FORMATETC) IDataObject.QueryGetData(FORMATETC) IDataObject.QueryGetData(FORMATETC)

确定数据对象是否能够呈现 FORMATETC 结构中所描述的数据。Determines whether the data object is capable of rendering the data described in the FORMATETC structure. 尝试执行粘贴或删除操作的对象可以在调用 GetData(FORMATETC, STGMEDIUM) 来获取操作是否成功的指示之前调用此方法。Objects attempting a paste or drop operation can call this method before calling GetData(FORMATETC, STGMEDIUM) to get an indication of whether the operation may be successful.

IDataObject.SetData(FORMATETC, STGMEDIUM, Boolean) IDataObject.SetData(FORMATETC, STGMEDIUM, Boolean) IDataObject.SetData(FORMATETC, STGMEDIUM, Boolean) IDataObject.SetData(FORMATETC, STGMEDIUM, Boolean)

将数据传输至实现此方法的对象。Transfers data to the object that implements this method. 此方法由包含数据源的对象调用。This method is called by an object that contains a data source.

适用于

另请参阅