Initial commit

This commit is contained in:
2014-04-30 17:33:21 -04:00
commit f965f46fb3
33 changed files with 2949 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
namespace Common.Wpf.HtmlTextBlock
{
public class HtmlTextBlock : TextBlock
{
public static readonly DependencyProperty HtmlProperty = DependencyProperty.Register("Html", typeof(string), typeof(HtmlTextBlock), new UIPropertyMetadata("Html", OnHtmlChanged));
public static void OnHtmlChanged(DependencyObject s, DependencyPropertyChangedEventArgs e)
{
HtmlTextBlock htmlTextBlock = (HtmlTextBlock) s;
Parse(htmlTextBlock, e.NewValue as string);
}
private static void Parse(HtmlTextBlock control, string value)
{
try
{
control.Inlines.Clear();
TextParser parser = new TextParser();
var lines = parser.Parse(control, value);
foreach (TextLine line in lines)
{
foreach (TextFragment fragment in line.FragmentList)
{
Run run = new Run(fragment.Text);
run.FontStyle = fragment.Style;
run.FontWeight = fragment.Weight;
run.FontSize = fragment.Size;
run.Foreground = fragment.Color;
control.Inlines.Add(run);
}
}
}
catch (Exception)
{
control.Inlines.Clear();
control.Text = value;
}
}
public string Html
{
get { return (string) GetValue(HtmlProperty); }
set { SetValue(HtmlProperty, value); }
}
}
}