My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
yesterday: Inspiring ted talk: Sugata Mitra: The child-driven education: "any teacher who can be replaced by a machine, should be": http://is.gd/eZRvi.
yesterday: Always so painful to look up the German article of a borrowed IT word: der Framework or das Framework? LEO won't tell me: http://is.gd/eZMeU.
yesterday: I know what podcast I'm listening to tomorrow on my way to work: John Resig on technometria: http://is.gd/eZJfq.
yesterday: C# CODE EXAMPLE: Extension method to sort a generic collection of objects: http://is.gd/eZG6n.
yesterday: C# CODE EXAMPLE: A simple class that represents a matching quiz item: http://is.gd/eZFZV.
yesterday: After-work 13K, two 5Ks under sub-four marathon pace: 23:27, 27:27, legs feel great: http://tanguay.info/run.
2 days ago: 6 yr old daughter's last 2 questions before falling asleep tonight: 1) Why are there humans? 2) Is there anything that doesn't have a name?
3 days ago: If you are a developer in Berlin and need to improve your English, I'm looking for groups to teach after work: http://tanguay.info/itenglish.
3 days ago: As far as I'm concerned, the singularity is already here, every time I wake up twitter tells me something amazing was created while I slept.
3 days ago: We're not suffering from information overload, we're suffering from faulty filtering.
3 days ago: Classic literature for free as nicely formatted 1-page or 2-page PDF downloads: http://www.planetebook.com/free-ebooks.asp.
WPF CODE EXAMPLE created on Sunday, February 21, 2010 permalink
How to format text in a WPF application (bold, italic, colored, hyperlinks, etc.)
I needed an easy way to display text with simple formatting (bold, italic, colors, hyperlinks) in a WPF application. This example gives you the basis to create custom markup that is converted into a FlowDocument. It is easy to create other codes which represent other formatting that you need for your application, copy and add a block in the switch statement.
XAML:
<Window x:Class="TestFlow23993.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <StackPanel Margin="10">
        <ContentControl x:Name="MainArea"/>
    </StackPanel>
</Window>

using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Controls;
using System.Windows.Input;
using System;
using System.Diagnostics;

namespace TestFlow23993
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();

            StackPanel sp = new StackPanel();
            sp.AddMarkedUpText("You want to {i:always} use this class so it is both {b:easy} and {b:straight-forward} to format documents. Here are some examples of {b:camel-case} strings: {ex:firstName}, {ex:lastName}, {ex:title}, and {ex:allowUserToFilterRows}.");
            sp.AddMarkedUpText("This is the second paragraph which allows you to link to {link:google>>>http://www.google.com}.");
            sp.AddMarkedUpText("Here's another paragraph with no formatting.");

            MainArea.Content = sp;
        }
    }

    public class FlowDocumentParser
    {
        private string markedUpText;
        private List<string> parts;
        private FlowDocument doc;

        public int FontSize { get; set; }
        public string FontFamily { get; set; }
        public TextAlignment TextAlignment { get; set; }

        public FlowDocumentParser(string markedUpText)
        {
            this.markedUpText = markedUpText;
            parts = markedUpText.Split(new char[] { '{', '}' }).ToList();
            SetDefaults();
        }

        void SetDefaults()
        {
            FontSize = 12;
            FontFamily = "Arial";
            TextAlignment = TextAlignment.Left;
        }

        public void BuildFlowDocument()
        {
            doc = new FlowDocument();
            doc.PagePadding = new Thickness(0);
            Paragraph paragraph = new Paragraph();
            paragraph.TextAlignment = TextAlignment;
            doc.Blocks.Add(paragraph);

            foreach (var part in parts)
            {
                //ITALIC, e.g. "{i:this is italic}"
                if (part.StartsWith("i:"))
                {
                    string text = part.ChopLeft("i:");
                    Run run = AddPart(paragraph, text);
                    run.FontStyle = FontStyles.Italic;
                }
                //BOLD, e.g. "{b:this is bold}"
                else if (part.StartsWith("b:"))
                {
                    string text = part.ChopLeft("b:");
                    Run run = AddPart(paragraph, text);
                    run.FontWeight = FontWeights.Bold;
                }
                //EXAMPLE TEXT, e.g. "{ex:this is an example}"
                else if (part.StartsWith("ex:"))
                {
                    string text = part.ChopLeft("ex:");
                    Run run = AddPart(paragraph, text);
                    run.FontWeight = FontWeights.Bold;
                    run.Foreground = new SolidColorBrush(Colors.Brown);
                }
                //HYPERLINK, e.g. "{link:google>>>http://www.google.com}"
                else if (part.StartsWith("link:"))
                {
                    string text = part.ChopLeft("link:");
                    List<string> pieces = text.SplitWithStringSeparator(">>>");
                    string linkText = pieces[0];
                    string linkUrl = pieces[1];
                    Run run = new Run(linkText);
                    run.FontSize = FontSize;
                    run.FontFamily = new FontFamily(FontFamily);
                    run.Foreground = new SolidColorBrush(Colors.Blue);
                    run.Cursor = Cursors.Hand;
                    Hyperlink hl = new Hyperlink(run);
                    hl.NavigateUri = new Uri(linkUrl);
                    hl.Foreground = new SolidColorBrush(Colors.Blue);
                    hl.RequestNavigate += new System.Windows.Navigation.RequestNavigateEventHandler(hl_RequestNavigate);
                    paragraph.Inlines.Add(hl);
                }
                else
                {
                    Run run = AddPart(paragraph, part);
                }
            }
        }

        void hl_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
        {
            Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
            e.Handled = true;
        }

        Run AddPart(Paragraph paragraph, string text)
        {
            Run run = new Run(text);
            paragraph.Inlines.Add(run);
            run.FontSize = FontSize;
            run.FontFamily = new FontFamily(FontFamily);
            return run;
        }


        public FlowDocument GetBuiltFlowDocument()
        {
            return doc;
        }

        public static FlowDocument GetFlowDocument(string markedUpText)
        {
            FlowDocumentParser fdp = new FlowDocumentParser(markedUpText);
            fdp.BuildFlowDocument();
            return fdp.GetBuiltFlowDocument();
        }
    }

    public static class StringHelpers
    {
        public static string ChopLeft(this string line, string removeThis)
        {
            int removeThisLength = removeThis.Length;
            if (line.Length >= removeThisLength)
            {
                if (line.StartsWith(removeThis))
                    return line.Substring(removeThisLength, line.Length - removeThisLength);
                else
                    return line;
            }
            else
                return line;
        }

        public static List<string> SplitWithStringSeparator(this string line, string separator)
        {
            return line.Split(new string[] { separator }, StringSplitOptions.None).ToList();
        }
    }

    public static class XamlHelpers
    {
        public static void AddMarkedUpText(this StackPanel sp, string markedUpText)
        {
            FlowDocumentScrollViewer fdsv = new FlowDocumentScrollViewer();

            FlowDocument fd = FlowDocumentParser.GetFlowDocument(markedUpText);
            fdsv.Document = fd;
            fdsv.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
            fdsv.Margin = new Thickness { Bottom = 10 };

            sp.Children.Add(fdsv);
        }
    }

}
need markup?