HtmlFormatHelper 类

定义

负责设置要共享或添加到剪贴板的 HTML 内容的格式。 还允许从内容中获取 HTML 片段。

public ref class HtmlFormatHelper abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class HtmlFormatHelper final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public static class HtmlFormatHelper
Public Class HtmlFormatHelper
继承
Object Platform::Object IInspectable HtmlFormatHelper
属性

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

if (shareOperation.data.contains(Windows.ApplicationModel.DataTransfer.StandardDataFormats.html)) {
    document.getElementById("htmlContentArea").className = "unhidden";
    
    shareOperation.data.getHtmlFormatAsync().then(function (html) {
        if (html !== null) {
            var htmlFragment = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.getStaticFragment(htmlFormat);

            // Set the innerHTML of the ifram to the HTML fragment.
            var iFrame = document.getElementById("htmlContent");
            iFrame.style.display = "";
            iFrame.contentDocument.documentElement.innerHTML = htmlFragment;
        } 
    });

    // Loop through any images and use the resourceMap to map each image element's src.
    var images = iFrame.contentDocument.documentElement.getElementsByTagName("img");
    if (images.length > 0) {
        shareOperation.data.getResourceMapAsync().done(function (resourceMap) {
            if (resourceMap.size > 0) {
                for (var i = 0, len = images.length; i < len; i++) {
                    var streamReference = resourceMap[images[i].getAttribute("src")];
                    if (streamReference) {
                        // Call a helper function to map the image element's src to a corresponding blob URL generated from the streamReference
                        setResourceMapURL(streamReference, images[i]);
                    }
                }
            }
        });
}
//shareOperation.reportCompleted();

注解

有关如何使用此类的详细信息,检查 DataPackage.SetHtmlFormat。 你可能还需要查看我们的主题 如何共享 HTML

方法

CreateHtmlFormat(String)

获取表示 HTML 内容的字符串,并添加必要的标头,以确保正确设置共享和剪贴板操作的格式。

GetStaticFragment(String)

获取表示 HTML 片段的字符串。

适用于