Click here to Skip to main content
13,094,732 members (82,894 online)
Click here to Skip to main content


34 bookmarked
Posted 7 Feb 2009

WPF HTML Supported TextBlock

This article describes HtmlTextBlock which is a WPF TextBlock that can parse a limited set of HTML tags and display them.
 * Created by SharpDevelop.
 * User: LYCJ
 * Date: 18/10/2007
 * Time: 23:26
 * To change this template use Tools | Options | Coding | Edit Standard Headers.

using System;
using System.Collections.Generic;
using System.Collections;

namespace QuickZip.MiniHtml2
	public class HtmlTagNode : IEnumerable
		protected bool isRoot;
		protected HtmlTag tag;
		protected List<HtmlTagNode> childTags;
		protected HtmlTagNode parentNode;
		///<summary> Gets the embedded HtmlTag of this node. <> </summary>
		public HtmlTag Tag { get { return tag; } }
		///<summary> Gets parent node of this node. <> </summary>
		public HtmlTagNode Parent { get { return parentNode; } }
		///<summary> Gets subnodes of this node. </summary>
		public List<HtmlTagNode> Items { get { return childTags; } }
		///<summary> Gets subnodes emuerator. </summary>
		public IEnumerator GetEnumerator() { return childTags.GetEnumerator(); }
		///<summary> Gets whether this node is root of all nodes. </summary>
		public bool IsRoot { get { return isRoot; } }
		///<summary> Gets whether this node contain other nodes. </summary>
		public bool isContainer { get { return childTags.Count > 0; } }
		public bool isBlock { get { return Defines.BuiltinTags[tag.ID].flags == HTMLFlag.Region; } }		
		public virtual bool CanAdd(HtmlTag aTag) 
			if (tag.IsEndTag)
				return false;
			if ((aTag.Name == '/' + tag.Name) ||
			    (aTag.Level < tag.Level))
				return true;
			return false;
		public HtmlTagNode Add(HtmlTag aTag)
			if (!CanAdd(aTag))
				throw new Exception("Cannot add here, check your coding.");
			HtmlTagNode retVal = new HtmlTagNode(this, aTag);
			if (aTag.Name == '/' + tag.Name)
				return Parent;
			else return retVal;
		///<summary> Constructor, hide from user view. </summary>
		private HtmlTagNode(HtmlTag aTag) { ;}
		///<summary> Constructor. </summary>
		public HtmlTagNode(HtmlTagNode aParentNode, HtmlTag aTag) : base()
			isRoot = false;
			parentNode = aParentNode;
			tag = aTag;
			childTags = new List<HtmlTagNode>();			
		public List<HtmlTag> ToHtmlTagList()
			List<HtmlTag> retVal = new List<HtmlTag>();
			foreach (HtmlTagNode subnode in this)
			return retVal;
		public override string ToString()
			return tag.ToString();
		///<summary> Debug this component. </summary>
		public void PrintItems()
			foreach (HtmlTag t in this)

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

Leung Yat Chun (Fainx)
Hong Kong Hong Kong
From the end of the Universe we have Fainx and Quick Zip. is stolen by and is the temporary site.
May Thy Lord Your God be blessed always.

DirectoryInfoEx - [1.0.27]
WPF FileExplorer3 - [3.0.19]
WPF HtmlTextBlock - [Codeplex]
WPF ListView MultiSelect - [0.4]
WPF UIEventHub MultiSelect/DragDrop w Touch support - [3.0]
WPF BreadcrumbFolderTextBox - [2.5]
WPF BreadcrumbTree and Breadcrumb - [dirkster's edition]
WPF Aero Titlebar - [0.2]

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 7 Feb 2009
Article Copyright 2009 by Leung Yat Chun (Fainx)
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid