Dela via


StandardDataFormats Class

Definition

Contains static properties that return string values. Each string corresponds to a known format ID. Use this class to avoid errors in using string constants to specify data formats.

public ref class StandardDataFormats abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class StandardDataFormats final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public static class StandardDataFormats
Public Class StandardDataFormats
Inheritance
Object Platform::Object IInspectable StandardDataFormats
Attributes

Windows requirements

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

Examples

This example shows how to retrieve shared text (by using StandardDataFormats.Text) or a shared file or folder (by using StandardDataFormats.StorageItems). For more examples, see the Clipboard sample and the ShareTarget sample.

public async Task ActivateAsync(ShareTargetActivatedEventArgs args)
{
    ShareOperation shareOperation = args.ShareOperation;
    if (shareOperation.Data.Contains(StandardDataFormats.Text))
    {
        string text = await shareOperation.Data.GetTextAsync();

        // To output the text from this example, you need a TextBlock control
        // with a name of "sharedContent".
        sharedContent.Text = "Text: " + text;
    }

    if (shareOperation.Data.Contains(StandardDataFormats.StorageItems)) 
    {
        shareOperation.ReportStarted();
        IReadOnlyList<IStorageItem> storageItems = null;
        storageItems = await shareOperation.Data.GetStorageItemsAsync();
        string fileList = String.Empty;

        for (int index = 0; index < storageItems.Count; index++) 
        {
            fileList += storageItems[index].Name;
                if (index < storageItems.Count - 1) {
                    fileList += ", ";
                }
            }

        // To output the text from this example, you need a TextBlock control
        // with a name of "sharedContent".
        sharedContent.Text += "StorageItems: " + fileList + Environment.NewLine;

        shareOperation.ReportCompleted();
    }

    Window.Current.Content = this;
    Window.Current.Activate();
}

Remarks

The DataPackage class supports several format types. Whenever you need to specify a format, we recommend using the properties of the StandardDataFormats class, instead of string values. Doing so ensures consistency between source and target applications.

The DataPackage class supports a number of legacy formats for interoperability between UWP app and desktop apps. To retrieve these formats, you pass one of the following strings to the DataPackageView.GetDataAsync method instead of a value from the StandardDataFormats class.

If format name is:GetDataAsync() retrieves:
"AnsiText"String for CF_TEXT.
"DeviceIndependentBitmap"Stream for HGLOBAL corresponding to CF_DIB.
"DeviceIndependentBitmapV5"Stream for HGLOBAL corresponding to CF_DIBV5.
"DataInterchangeFormat"Stream for HGLOBAL corresponding to CF_DIF.
"EnhancedMetafile"Stream for HENHMETAFILE corresponding to CF_ENHMETAFILE.
"Locale"Stream for HGLOBAL corresponding to CF_LOCALE
"OEMText"String for CF_OEMTEXT.
"PenData"Stream for HGLOBAL corresponding to CF_PENDATA
"RiffAudio"Stream for HGLOBAL corresponding to CF_RIFF.
"SymbolicLink"Stream for HGLOBAL corresponding to CF_SYLK.
"TaggedImageFileFormat"Stream for HGLOBAL corresponding to CF_TIFF.
"WaveAudio"Stream for HGLOBAL corresponding to CF_WAVE.

The Windows Runtime provides limited support for metafiles. Specifically, the Windows Runtime:

  • Supports rendering metafiles, but not creating them.
  • Supports the CF_ENHMETAFILE format ("EnhancedMetafile"), but not CF_METAFILEPICT.
  • Supports requesting data in "EnhancedMetafile" format, but not providing it; that is, calling SetData("EnhancedMetafile", <data>) won't work.
  • Provides limited support through the clipboard API for exchanging metafiles between UWP app and desktop apps.

Version history

Windows version SDK version Value added
1803 17134 UserActivityJsonArray

Properties

ApplicationLink

A read-only property that returns the format ID string value corresponding to the activation link format.

Bitmap

A read-only property that returns the format ID string value corresponding to the Bitmap format.

Html

A read-only property that returns the format ID string value corresponding to the HTML format.

Rtf

A read-only property that returns the format ID string value corresponding to the Rich Text Format (RTF).

StorageItems

A read-only property that returns the format ID string value corresponding to the storage item format (for files and folders).

Text

A read-only property that returns the format ID string value corresponding to the Text format.

Uri

Note

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

A read-only property that returns the format ID string value corresponding to the Uniform Resource Identifier (URI) format.

UserActivityJsonArray

A read-only property that returns the format ID string value corresponding to the UserActivity JSON array format.

WebLink

A read-only property that returns the format ID string value corresponding to the web link format.

Applies to