Пример #1
0
        /// <summary>
        /// Handles the HTML has changed, converts it and attach to the attached RichTextBlock.
        /// </summary>
        /// <param name="d">The RichTextBlock.</param>
        /// <param name="e">The <see cref="DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
        private static async void HtmlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            RichTextBlock richText = d as RichTextBlock;
            string        html     = e.NewValue as string;

            if (richText != null && !string.IsNullOrEmpty(html))
            {
                try
                {
                    if (!ContainsHtmlTags(html))
                    {
                        html = html.Replace("\r\n", "<br/>");
                        html = html.Replace("\n\r", "<br/>");
                        html = html.Replace("\n", "<br/>");
                    }

                    string xaml = await Html2XamlProcessor.ConvertToXaml(html);

                    ChangeRichTextBlockContents(richText, xaml);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                    try
                    {
                        ChangeRichTextBlockContents(richText, GetErrorXaml(ex, html));
                    }
                    catch
                    {
                        Debug.WriteLine(ex);
                    }
                }
            }
        }
Пример #2
0
        private static string ConvertToXamlPrivate(string html)
        {
            html = PreprocessEntities(html);

            HtmlDocument document = new HtmlDocument();
            document.LoadHtml(html);

            var processor = new Html2XamlProcessor();
            return processor.ConvertHtml(document);
        }
Пример #3
0
        private static string ConvertToXamlPrivate(string html)
        {
            html = PreprocessEntities(html);

            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(html);

            var processor = new Html2XamlProcessor();

            return(processor.ConvertHtml(document));
        }