Esempio n. 1
0
        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);
            }
        }
Esempio n. 2
0
        async void PasteButton_Click(object sender, RoutedEventArgs e)
        {
            rootPage.NotifyUser("", NotifyType.StatusMessage);
            OutputText.Text            = "Content in the clipboard: ";
            OutputResourceMapKeys.Text = "";
            OutputHtml.NavigateToString("<HTML></HTML>");

            var dataPackageView = Windows.ApplicationModel.DataTransfer.Clipboard.GetContent();

            if (dataPackageView.Contains(StandardDataFormats.Text))
            {
                try
                {
                    var text = await dataPackageView.GetTextAsync();

                    OutputText.Text = "Text: " + Environment.NewLine + text;
                }
                catch (Exception ex)
                {
                    rootPage.NotifyUser("Error retrieving Text format from Clipboard: " + ex.Message, NotifyType.ErrorMessage);
                }
            }
            else
            {
                OutputText.Text = "Text: " + Environment.NewLine + "Text format is not available in clipboard";
            }



            if (dataPackageView.Contains(StandardDataFormats.Html))
            {
                this.DisplayResourceMapAsync(dataPackageView);

                string htmlFormat = null;
                try
                {
                    htmlFormat = await dataPackageView.GetHtmlFormatAsync();
                }
                catch (Exception ex)
                {
                    rootPage.NotifyUser("Error retrieving HTML format from Clipboard: " + ex.Message, NotifyType.ErrorMessage);
                }

                if (htmlFormat != null)
                {
                    string htmlFragment = HtmlFormatHelper.GetStaticFragment(htmlFormat);
                    OutputHtml.NavigateToString("HTML:<br/ > " + htmlFragment);
                }
            }
            else
            {
                OutputHtml.NavigateToString("HTML:<br/ > HTML format is not available in clipboard");
            }
        }