Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

WPF HTML Supported TextBlock

, 7 Feb 2009 LGPL3
This article describes HtmlTextBlock which is a WPF TextBlock that can parse a limited set of HTML tags and display them.
using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Collections.Generic;

namespace QuickZip.MiniHtml2

    public class CurrentStateType
        private List<HtmlTag> activeStyle = new List<HtmlTag>();
        private bool bold;
        private bool italic;
        private bool underline;
        private string hyperlink;

        public bool Bold { get { return bold; } }
        public bool Italic { get { return italic; } }
        public bool Underline { get { return underline; } }
        public string HyperLink { get { return hyperlink; } }

        public void UpdateStyle(HtmlTag aTag)
            if (!aTag.IsEndTag)
                for (int i = activeStyle.Count - 1; i >= 0; i--)
                    if ('/' + activeStyle[i].Name == aTag.Name)

        private void updateStyle()
            bold = false;
            italic = false;
            underline = false;
            hyperlink = "";

            foreach (HtmlTag aTag in activeStyle)
                switch (aTag.Name)
                    case "b": bold = true; break;
                    case "i": italic = true; break;
                    case "u": underline = true; break;
                    case "a": if (aTag.Contains("href")) hyperlink = aTag["href"]; break;

        public CurrentStateType()



By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


About the Author

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150123.1 | Last Updated 7 Feb 2009
Article Copyright 2009 by Leung Yat Chun
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid