Share via


HtmlFormatHelper Classe

Définition

Responsable de la mise en forme du contenu HTML que vous souhaitez partager ou ajouter au Presse-papiers. Vous permet également d’obtenir des fragments HTML à partir du contenu.

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
Héritage
Object Platform::Object IInspectable HtmlFormatHelper
Attributs

Configuration requise pour Windows

Famille d’appareils
Windows 10 (introduit dans 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduit dans v1.0)

Exemples

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();

Remarques

Pour plus d’informations sur l’utilisation de cette classe, case activée DataPackage.SetHtmlFormat. Vous pouvez également consulter notre rubrique Comment partager du code HTML.

Méthodes

CreateHtmlFormat(String)

Prend une chaîne qui représente le contenu HTML et ajoute les en-têtes nécessaires pour s’assurer qu’il est correctement mis en forme pour les opérations de partage et de Presse-papiers.

GetStaticFragment(String)

Obtient une chaîne qui représente un fragment HTML.

S’applique à