Dela via


DataPackage Class

Definition

Contains the data that a user wants to exchange with another app.

public ref class DataPackage sealed
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class DataPackage final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class DataPackage final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class DataPackage final
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class DataPackage
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class DataPackage
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class DataPackage
function DataPackage()
Public NotInheritable Class DataPackage
Inheritance
Object Platform::Object IInspectable DataPackage
Attributes

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Examples

//To see this code in action, add a call to ShareSourceLoad to your constructor or other
//initializing function.
private void ShareSourceLoad()
{
    DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
}

private void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Share Text Example";
    request.Data.Properties.Description = "An example of how to share text.";
    request.Data.SetText("Hello World!");
}

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.

Version history

Windows version SDK version Value added
1703 15063 ShareCompleted
2004 19041 ShareCanceled

Constructors

DataPackage()

Constructor that creates a new DataPackage.

Properties

Properties

Allows you to get and set properties like the title of the content being shared.

RequestedOperation

Specifies the DataPackageOperation (none, move, copy, or link) for the operation.

ResourceMap

Maps a URI to a file. Used to ensure that referenced content (such as an image) in HTML content is added to the DataPackage.

Methods

GetView()

Returns a DataPackageView object. This object is a read-only copy of the DataPackage object.

SetApplicationLink(Uri)

Sets the application link that a DataPackage contains.

SetBitmap(RandomAccessStreamReference)

Sets the bitmap image contained in the DataPackage.

SetData(String, Object)

Sets the data contained in the DataPackage in a RandomAccessStream format.

SetDataProvider(String, DataProviderHandler)

Sets a delegate to handle requests from the target app.

SetHtmlFormat(String)

Adds HTML content to the DataPackage.

SetRtf(String)

Sets the Rich Text Format (RTF) content that is contained in a DataPackage.

SetStorageItems(IIterable<IStorageItem>, Boolean)

Adds files and folders to a DataPackage.

SetStorageItems(IIterable<IStorageItem>)

Sets the files and folders contained in a DataPackage.

SetText(String)

Sets the text that a DataPackage contains.

SetUri(Uri)

Note

SetUri may be altered or unavailable for releases after Windows 8.1. Instead, use ApplicationLink or WebLink.

Sets the Uniform Resource Identifier (URI) that is contained in the DataPackage.

SetWebLink(Uri)

Sets the web link that a DataPackage contains.

Events

Destroyed

Occurs when the DataPackage is destroyed.

OperationCompleted

Occurs when a paste operation is completed.

ShareCanceled

Raised when a share is canceled.

ShareCompleted

An event that is triggered when a share is completed. Shares can be sent to an app, a provider, or a contact.

Applies to

See also