Contains the data that a user wants to exchange with another app.
Syntax
var dataPackage = new Windows.ApplicationModel.DataTransfer.DataPackage();
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- DualApiPartitionAttribute()
- MarshalingBehaviorAttribute(Agile)
- VersionAttribute(NTDDI_WIN8)
Members
The DataPackage class has these types of members:
Constructors
The DataPackage class has these constructors.
| Constructor | Description |
|---|---|
| DataPackage | Constructor that creates a new DataPackage. |
Events
The DataPackage class has these events.
| Event | Description |
|---|---|
| Destroyed | Occurs when the DataPackage is destroyed. |
| OperationCompleted | Occurs when a paste operation is completed. |
Methods
The DataPackage class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.
| Method | Description |
|---|---|
| GetView | Returns a DataPackageView object. This object is a read-only copy of the DataPackage object. |
| SetBitmap | Sets the bitmap image contained in the DataPackage. |
| SetData | Sets the data contained in the DataPackage in a RandomAccessStream format. |
| SetDataProvider | Sets a delegate to handle requests from the target app. |
| SetHtmlFormat | Adds HTML content to the DataPackage. |
| SetRtf | Sets the Rich Text Format (RTF) content that is contained in a DataPackage. |
| SetStorageItems(IIterable(IStorageItem)) | Sets the files and folders contained in a DataPackage. |
| SetStorageItems(IIterable(IStorageItem), Boolean) | Adds files and folders to a DataPackage. |
| SetText | Sets the text that a DataPackage contains. |
| SetUri | Sets the Uniform Resource Identifier (URI) that is contained in the DataPackage. |
Properties
The DataPackage class has these properties.
| Property | Access type | Description |
|---|---|---|
| Read-only | Allows you to get and set properties like the title of the content being shared. | |
| Read/write | Specifies the DataPackageOperation (none, move, copy, or link) for the operation. | |
| Read-only | Maps a URI to a file. Used to ensure that referenced content (such as an image) in HTML content is added to the DataPackage. |
Remarks
During a share operation, the source app puts the data being shared in a DataPackage object and sends that object to the target app for processing. The DataPackage class includes a number of methods to support the following default formats: text, Rtf, Html, Bitmap, and StorageItems. It also has methods to support custom data formats. To use these formats, both the source app and target app must already be aware that the custom format exists.
Source apps have the option of using SetDataProvider to assign a delegate to a DataPackage, instead of providing the data immediately. This process is useful when the source app supports a given format but does not want to generate the data unless the target app requests the data. For example, a source app might support a variety of image formats for sharing photos. Instead of creating multiple copies of each image using these formats, the source app can use a delegate that is called when the target app requests a specific format type.
Target apps can use the DataPackageView object to acquire the data being shared. In addition, these apps can use the AvailableFormats property to identify which formats the DataPackageView supports, or use the Contains method to query for a specific format.
Windows Phone 8
This API is supported in native apps only.
Examples
function registerForShare() { var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView(); dataTransferManager.addEventListener("datarequested", shareTextHandler); } function shareTextHandler(e) { var request = e.request; request.data.properties.title = "Share Text Example"; request.data.properties.description = "A demonstration that shows how to share."; request.data.setText("Hello World!"); }
Requirements
|
Minimum supported client | Windows 8 [Windows Store apps, desktop apps] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps, desktop apps] |
|
Minimum supported phone | Windows Phone 8 |
|
Namespace |
|
|
Metadata |
|
Build date: 2/25/2013