Click here to Skip to main content
15,896,514 members
Articles / Desktop Programming / WPF

SharpVectors - SVG# Reloaded: An Introduction

Rate me:
Please Sign up or sign in to vote.
4.98/5 (33 votes)
17 Nov 2010BSD10 min read 206.1K   21.7K   101  
A C# library for converting SVG to WPF and viewing SVG files in WPF Applications
using System;
using System.Xml;

using SharpVectors.Dom.Css;

namespace SharpVectors.Dom.Svg
{
	public sealed class SvgLinearGradientElement : SvgGradientElement, ISvgLinearGradientElement
	{
        private ISvgAnimatedLength x1;
        private ISvgAnimatedLength y1;
        private ISvgAnimatedLength x2;
        private ISvgAnimatedLength y2;

		public SvgLinearGradientElement(string prefix, string localname, string ns, SvgDocument doc)
			: base(prefix, localname, ns, doc)
		{
		}

		#region ISvgLinearGradientElement Members

		public ISvgAnimatedLength X1
		{
			get
			{
				if (!HasAttribute("x1") && ReferencedElement != null)
				{
					return ReferencedElement.X1;
				}
				else
				{
					if (x1 == null)
					{
						x1 = new SvgAnimatedLength(this, "x1", SvgLengthDirection.Horizontal, "0%");
					}

					return x1;
				}
			}
		}

		public ISvgAnimatedLength Y1
		{
			get
			{
				if (!HasAttribute("y1") && ReferencedElement != null)
				{
					return ReferencedElement.Y1;
				}
				else
				{

					if (y1 == null)
					{
						y1 = new SvgAnimatedLength(this, "y1", SvgLengthDirection.Vertical, "0%");
					}

					return y1;
				}
			}
		}

		public ISvgAnimatedLength X2
		{
			get
			{
				if (!HasAttribute("x2") && ReferencedElement != null)
				{
					return ReferencedElement.X2;
				}
				else
				{

					if (x2 == null)
					{
						x2 = new SvgAnimatedLength(this, "x2", SvgLengthDirection.Horizontal, "100%");
					}

					return x2;
				}
			}
		}

		public ISvgAnimatedLength Y2
		{
			get
			{
				if (!HasAttribute("y2") && ReferencedElement != null)
				{
					return ReferencedElement.Y2;
				}
				else
				{   
					if (y2 == null)
					{
						y2 = new SvgAnimatedLength(this, "y2", SvgLengthDirection.Vertical, "0%");
					}

					return y2;
				}
			}
		}
		#endregion

		#region ISvgURIReference Members

		public new SvgLinearGradientElement ReferencedElement
		{
			get
			{
				return base.ReferencedElement as SvgLinearGradientElement;
			}
		}

		#endregion

		#region Update handling
		/*public override void OnAttributeChange(XmlNodeChangedAction action, XmlAttribute attribute)
		{
			base.OnAttributeChange(action, attribute);

			if(attribute.NamespaceURI.Length == 0)
			{
				switch(attribute.LocalName)
				{
					case "x1":
						x1 = null;
						break;
					case "y1":
						y1 = null;
						break;
					case "x2":
						x2 = null;
						break;
					case "y2":
						y2 = null;
						break;
				}
			}
		}*/
		#endregion
	}
}

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.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Engineer
Japan Japan
Systems Engineer

Comments and Discussions