HtmlFormatHelper.CreateHtmlFormat(String) 方法

定义

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

public:
 static Platform::String ^ CreateHtmlFormat(Platform::String ^ htmlFragment);
 static winrt::hstring CreateHtmlFormat(winrt::hstring const& htmlFragment);
public static string CreateHtmlFormat(string htmlFragment);
function createHtmlFormat(htmlFragment)
Public Shared Function CreateHtmlFormat (htmlFragment As String) As String

参数

htmlFragment
String

Platform::String

winrt::hstring

表示 HTML 内容的字符串。

返回

String

Platform::String

winrt::hstring

一个表示格式化 HTML 的字符串。

示例

public void ShareSourceLoad()
{
    DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
}

async void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
    string htmlExample = "<p>Here is our store logo: <img src='assets/logo.png'>.</p>";
    string fileExample = "assets\\logo.png";
    RandomAccessStreamReference streamRef = null;
    Windows.Storage.StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileExample);
    try
    {
        streamRef = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(file);
    }
    catch (Exception ex)
    {
        // TODO: Handle the exception.
    }
    string htmlFormat = Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.CreateHtmlFormat(htmlExample);
    DataRequest request = e.Request;
    request.Data.Properties.Title = "Share HTML Example";
    request.Data.Properties.Description = "An example of how to share HTML.";
    request.Data.SetHtmlFormat(htmlFormat);
    request.Data.ResourceMap[fileExample] = streamRef;
}

适用于