示例#1
0
        public void DrawHtml()
        {
            if (_canvas == null)
            {
                return;
            }
            _canvas.Blocks.Clear();

            Paragraph p = new Paragraph
            {
                LineHeight = this.LineHeight,
                FontSize   = this.FontSize
            };
            Span span;

            if (Regex.IsMatch(Html, Utils.UrlRegex, RegexOptions.IgnoreCase))
            {
                span = HtmlExts.FormatText(Html);
            }
            else
            {
                span = new Span();
                span.Inlines.Add(new Run()
                {
                    Text = HtmlUtilities.ConvertToText(Html)
                });
            }
            p.Inlines.Add(span);
            _canvas.Blocks.Add(p);
        }
示例#2
0
 private static void OnHtmlChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue != null || e.OldValue != null)
     {
         if (_canvas == null)
         {
             return;
         }
         _canvas.Blocks.Clear();
         Paragraph p = new Paragraph();
         Span      span;
         if (e.NewValue != null)
         {
             string html = e.NewValue.ToString();
             if (Regex.IsMatch(html, Utils.UrlRegex, RegexOptions.IgnoreCase))
             {
                 span = HtmlExts.FormatText(html);
             }
             else
             {
                 span = new Span();
                 span.Inlines.Add(new Run()
                 {
                     Text = HtmlUtilities.ConvertToText(html)
                 });
             }
             p.Inlines.Add(span);
         }
         _canvas.Blocks.Add(p);
     }
 }