共用方式為


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;
}

適用於