<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Matt Manela's Blog : XAML</title><link>http://blogs.msdn.com/matt/archive/tags/XAML/default.aspx</link><description>Tags: XAML</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Converting RTF to HTML</title><link>http://blogs.msdn.com/matt/archive/2009/09/28/converting-rtf-to-html.aspx</link><pubDate>Mon, 28 Sep 2009 21:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9900386</guid><dc:creator>MattManela</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/matt/comments/9900386.aspx</comments><wfw:commentRss>http://blogs.msdn.com/matt/commentrss.aspx?PostID=9900386</wfw:commentRss><description>&lt;P&gt;Have you ever had the desire to convert some RTF text into HTML? Probably not. But if you do, then you are in luck! I recently had the need to do this conversion and after some searching found out a way to do it by enhancing a sample distributed in the MSDN library.&amp;nbsp; The sample is called: &lt;A href="http://msdn.microsoft.com/en-us/library/aa972129.aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa972129.aspx"&gt;XAML to HTML Conversion Demo&lt;/A&gt;.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The sample has code which converts HTML to and from a XAML Flow Document.&amp;nbsp; But this doesn’t make things easier until you realize that there is a way to convert RTF to XAML easily. The key is to use &lt;A title=http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx"&gt;System.Windows.Controls.RichTextBox&lt;/A&gt; which can load RTF from a stream and save it as XAML.&amp;nbsp; This conversion is shown below:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ConvertRtfToXaml(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; rtfText)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            var richTextBox = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; RichTextBox();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt; (&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;.IsNullOrEmpty(rtfText)) &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; "&lt;SPAN style="COLOR: #8b0000"&gt;&lt;/SPAN&gt;";
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            var textRange = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var rtfMemoryStream = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; MemoryStream())
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var rtfStreamWriter = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; StreamWriter(rtfMemoryStream))
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                    rtfStreamWriter.Write(rtfText);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                    rtfStreamWriter.Flush();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                    rtfMemoryStream.Seek(0, SeekOrigin.Begin);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                    textRange.Load(rtfMemoryStream, DataFormats.Rtf);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var rtfMemoryStream = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; MemoryStream())
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                textRange = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                textRange.Save(rtfMemoryStream, DataFormats.Xaml);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                rtfMemoryStream.Seek(0, SeekOrigin.Begin);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                &lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt; (var rtfStreamReader = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; StreamReader(rtfMemoryStream))
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                    &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; rtfStreamReader.ReadToEnd();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;                }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        }&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;With this code we have all we need to convert RTF to HTML. I modified the sample to add this RTF To XAML conversation and then I run that XAML through HTML converter which results in the HTML text. I added an interface to these conversion utilities and converted the sample into a library so that I would be able to use it from other projects.&amp;nbsp; Here is the interface:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt; &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;interface&lt;/SPAN&gt; IMarkupConverter
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;    {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ConvertXamlToHtml(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; xamlText);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ConvertHtmlToXaml(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; htmlText);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ConvertRtfToHtml(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; rtfText);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;    }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;    &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; MarkupConverter : IMarkupConverter
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;    {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ConvertXamlToHtml(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; xamlText)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; HtmlFromXamlConverter.ConvertXamlToHtml(xamlText, &lt;SPAN style="COLOR: #0000ff"&gt;false&lt;/SPAN&gt;);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ConvertHtmlToXaml(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; htmlText)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; HtmlToXamlConverter.ConvertHtmlToXaml(htmlText, &lt;SPAN style="COLOR: #0000ff"&gt;true&lt;/SPAN&gt;);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ConvertRtfToHtml(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; rtfText)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        {
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;            &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; RtfToHtmlConverter.ConvertRtfToHtml(rtfText);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;    }&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;With this I am now able to convert from RTF to HTML.&amp;nbsp; However, there is one catch - the conversion uses the RichTextBox WPF control which requires a single threaded apartment (STA).&amp;nbsp; Therefore in order to run your code that calls the ConvertRtfToHtml function, it must also be running in a STA.&amp;nbsp; If you can’t have your program run in a STA then you must create a new STA thread to run the conversion. Like this:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: #cecece 1px solid; BORDER-LEFT: #cecece 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #fbfbfb; MIN-HEIGHT: 40px; PADDING-LEFT: 5px; WIDTH: 650px; PADDING-RIGHT: 5px; OVERFLOW: auto; BORDER-TOP: #cecece 1px solid; BORDER-RIGHT: #cecece 1px solid; PADDING-TOP: 5px"&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;MarkupConverter markupConverter = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; MarkupConverter();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; ConvertRtfToHtml(&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; rtfText)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;{
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;   var thread = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; Thread(ConvertRtfInSTAThread);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;   var threadData = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; ConvertRtfThreadData { RtfText = rtfText };
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;   thread.SetApartmentState(ApartmentState.STA);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;   thread.Start(threadData);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;   thread.Join();
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;   &lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt; threadData.HtmlText;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;}
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt; ConvertRtfInSTAThread(&lt;SPAN style="COLOR: #0000ff"&gt;object&lt;/SPAN&gt; rtf)
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;{
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;   var threadData = rtf &lt;SPAN style="COLOR: #0000ff"&gt;as&lt;/SPAN&gt; ConvertRtfThreadData;
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;   threadData.HtmlText = markupConverter.ConvertRtfToHtml(threadData.RtfText);
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;}
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;        
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt; ConvertRtfThreadData
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;{
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;   &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; RtfText { &lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;; }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;   &lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt; HtmlText { &lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;; &lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;; }
&lt;/PRE&gt;&lt;PRE style="BACKGROUND-COLOR: #fbfbfb; MARGIN: 0em; WIDTH: 100%; FONT-FAMILY: consolas,'Courier New',courier,monospace; FONT-SIZE: 11px"&gt;}&lt;/PRE&gt;&lt;/PRE&gt;
&lt;P&gt;Here is the zip contain the code for the Markup converter: &lt;A href="http://blogs.msdn.com/matt/attachment/9900386.ashx" mce_href="http://blogs.msdn.com/matt/attachment/9900386.ashx"&gt;MarkupConverter.zip&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9900386" width="1" height="1"&gt;</description><enclosure url="http://blogs.msdn.com/matt/attachment/9900386.ashx" length="64021" type="application/x-zip-compressed" /><category domain="http://blogs.msdn.com/matt/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/matt/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/matt/archive/tags/XAML/default.aspx">XAML</category><category domain="http://blogs.msdn.com/matt/archive/tags/RTF/default.aspx">RTF</category><category domain="http://blogs.msdn.com/matt/archive/tags/HTML/default.aspx">HTML</category></item><item><title>The two most important WPF Tools</title><link>http://blogs.msdn.com/matt/archive/2008/08/01/the-two-most-important-wpf-tools.aspx</link><pubDate>Fri, 01 Aug 2008 18:49:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8800484</guid><dc:creator>MattManela</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/matt/comments/8800484.aspx</comments><wfw:commentRss>http://blogs.msdn.com/matt/commentrss.aspx?PostID=8800484</wfw:commentRss><description>&lt;P&gt;I have been working a lot with WPF and I found the following two FREE tools to be extremely helpful.&lt;/P&gt;
&lt;P&gt;The first is:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/llobo/archive/2007/12/19/xamlpadx-v3-0.aspx" mce_href="http://blogs.msdn.com/llobo/archive/2007/12/19/xamlpadx-v3-0.aspx"&gt;&lt;STRONG&gt;XamlPadX&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt; - (&lt;/STRONG&gt;&lt;A title=http://blogs.msdn.com/llobo/archive/2007/12/19/xamlpadx-v3-0.aspx href="http://blogs.msdn.com/llobo/archive/2007/12/19/xamlpadx-v3-0.aspx" mce_href="http://blogs.msdn.com/llobo/archive/2007/12/19/xamlpadx-v3-0.aspx"&gt;&lt;STRONG&gt;http://blogs.msdn.com/llobo/archive/2007/12/19/xamlpadx-v3-0.aspx&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This is an enhanced version of XamlPad which comes with the .NET SDK.&amp;nbsp; This is a light weight tool which parses and renders XAML code visually.&amp;nbsp; It adds (in addition to just rendering XAML) a command interpreter, visual tree explorer, add-in support and much more.&lt;/P&gt;
&lt;P&gt;I find this tool very usefull when I want to just play around with XAML and see how things render.&amp;nbsp; It is quicker than firing up VS and using the Cider designer.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://blogs.msdn.com/llobo/archive/2007/12/19/xamlpadx-v3-0.aspx" mce_href="http://blogs.msdn.com/llobo/archive/2007/12/19/xamlpadx-v3-0.aspx"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=247 alt=image src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/TwomostimportantWPFTools_7BAA/image_6.png" width=354 border=0 mce_src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/TwomostimportantWPFTools_7BAA/image_6.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;The other tool is:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.blois.us/Snoop/" mce_href="http://www.blois.us/Snoop/"&gt;&lt;STRONG&gt;Snoop&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt; - (&lt;/STRONG&gt;&lt;A title=http://www.blois.us/Snoop/ href="http://www.blois.us/Snoop/" mce_href="http://www.blois.us/Snoop/"&gt;&lt;STRONG&gt;http://www.blois.us/Snoop/&lt;/STRONG&gt;&lt;/A&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Snoop is a visual debugger for WPF application.&amp;nbsp; When any WPF application is running you can use snoop to view its visual tree and all the elements properties.&amp;nbsp; You can search for any element, view its properties, change its properties and see how the application changes.&lt;/P&gt;
&lt;P&gt;This program really helps in understanding what is going on in your WPF application and finding problems.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.blois.us/Snoop/" mce_href="http://www.blois.us/Snoop/"&gt;&lt;IMG style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" height=294 alt=image src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/TwomostimportantWPFTools_7BAA/image_5.png" width=354 border=0 mce_src="http://blogs.msdn.com/blogfiles/matt/WindowsLiveWriter/TwomostimportantWPFTools_7BAA/image_5.png"&gt;&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8800484" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/matt/archive/tags/Programming/default.aspx">Programming</category><category domain="http://blogs.msdn.com/matt/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/matt/archive/tags/XAML/default.aspx">XAML</category><category domain="http://blogs.msdn.com/matt/archive/tags/Tools/default.aspx">Tools</category></item></channel></rss>