void CopyButton_Click(object sender, RoutedEventArgs e)
{
OutputText.Text = "";
OutputResourceMapKeys.Text = "";
OutputHtml.NavigateToString("<HTML></HTML>");
// Set the content to DataPackage as html format
string htmlFormat = HtmlFormatHelper.CreateHtmlFormat(this.htmlFragment);
var dataPackage = new DataPackage();
dataPackage.SetHtmlFormat(htmlFormat);
// Set the content to DataPackage as (plain) text format
string plainText = HtmlUtilities.ConvertToText(this.htmlFragment);
dataPackage.SetText(plainText);
// Populate resourceMap with StreamReference objects corresponding to local image files embedded in HTML
var imgUri = new Uri(imgSrc);
var imgRef = RandomAccessStreamReference.CreateFromUri(imgUri);
dataPackage.ResourceMap[imgSrc] = imgRef;
try
{
// Set the DataPackage to clipboard.
Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage);
OutputText.Text = "Text and HTML formats have been copied to clipboard. ";
}
catch (Exception ex)
{
// Copying data to Clipboard can potentially fail - for example, if another application is holding Clipboard open
rootPage.NotifyUser("Error copying content to Clipboard: " + ex.Message + ". Try again", NotifyType.ErrorMessage);
}
}