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
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: 21:42
 * To change this template use Tools | Options | Coding | Edit Standard Headers.

using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing;
using System.Text;

namespace QuickZip.MiniHtml2
	/// <summary>
	/// Represent an element Tag in Html code
	/// </summary>
	public class HtmlTag
        private string name;                                     //HtmlTag name without <>        
        private PropertyList variables = new PropertyList();     //Variable List and values
        ///<summary> Gets HtmlTag ID in BuiltInTags. (without <>) </summary>
        internal Int32 ID { get { return Math.Abs(Utils.LocateTag(Utils.RemoveFrontSlash(name))); } }
        ///<summary> Gets HtmlTag Level in BuiltInTags. (without <>) </summary>
        internal Int32 Level { get { if (ID == -1) return 0; else return Defines.BuiltinTags[ID].tagLevel; } }
        internal bool IsEndTag { get {  return ((name.IndexOf('/') == 0) ||(variables.Contains('/'))); } }
        ///<summary> Gets HtmlTag name. (without <>) </summary>
        public string Name { get { return name; } }
        ///<summary> Gets variable value. </summary>
        public string this[string key] { get { return variables[key].value; } }        
        ///<summary> Gets whether variable list contains the specified key. </summary>
        public bool Contains(string key) { return variables.Contains(key); }
        ///<summary> Returns the string representation of the value of this instance.  </summary>
		public override string ToString()
			return String.Format("<{0}> : {1}", name, variables.ToString());
        /// <summary>
        /// Initialite procedure, can be used by child tags.
        /// </summary>
        protected void init(string aName, PropertyList aVariables)
            name = aName.ToLower();
            if (aVariables == null)
                variables = new PropertyList();
                variables = aVariables;            
		///<summary> Constructor. </summary>
		public HtmlTag(string aName, string aVarString)
			init(aName, PropertyList.FromString(aVarString));
		public HtmlTag(string aText)
			PropertyList aList = new PropertyList();
			aList.Add("value", aText);
			init("text", aList);

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 | Mobile
Web02 | 2.8.140826.1 | Last Updated 7 Feb 2009
Article Copyright 2009 by Leung Yat Chun
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid