Exemplo n.º 1
0
        void ReadStops(XElement e, List <GradientStop> stops)
        {
            var ns = e.Name.Namespace;

            foreach (var se in e.Elements(ns + "stop"))
            {
                var s = new GradientStop();
                s.Offset = ReadNumber(se.Attribute("offset"));
                double alpha          = 1.0;
                var    styleAttribute = se.Attribute("style");
                if (styleAttribute != null)
                {
                    var styleSettings = styleAttribute.Value.Split(';');
                    foreach (var style in styleSettings)
                    {
                        if (style.Contains("stop-color") && style.IndexOf(':') != -1)
                        {
                            s.Color = ReadColor(style.Substring(style.IndexOf(':') + 1));
                        }
                        else if (style.Contains("stop-opacity") && style.IndexOf(':') != -1)
                        {
                            alpha = ReadNumber(style.Substring(style.IndexOf(':') + 1));
                        }
                    }
                }
                var stopColorAttribute = se.Attribute("stop-color");
                if (stopColorAttribute != null)
                {
                    s.Color = ReadColor(stopColorAttribute.Value);
                }
                var opacityAttribute = se.Attribute("stop-opacity");
                if (opacityAttribute != null)
                {
                    alpha = ReadNumber(opacityAttribute.Value);
                }
                s.Color.Alpha = alpha;
                stops.Add(s);
            }
            stops.Sort((x, y) => x.Offset.CompareTo(y.Offset));
        }
Exemplo n.º 2
0
		void ReadStops (XElement e, List<GradientStop> stops)
		{
			var ns = e.Name.Namespace;
			foreach (var se in e.Elements (ns + "stop")) {
				var s = new GradientStop ();
				s.Offset = ReadNumber (se.Attribute ("offset"));
				double alpha = 1.0;
				var styleAttribute = se.Attribute("style");
				if (styleAttribute != null)
				{
					var styleSettings = styleAttribute.Value.Split(';');
					foreach(var style in styleSettings)
					{
						if (style.Contains("stop-color") && style.IndexOf(':') != -1)
						{
							s.Color = ReadColor(style.Substring(style.IndexOf(':')+1));
						}
						else if (style.Contains("stop-opacity") && style.IndexOf(':') != -1)
						{
							alpha = ReadNumber(style.Substring(style.IndexOf(':')+1));
						}
					}
				}
				var stopColorAttribute = se.Attribute("stop-color");
				if (stopColorAttribute != null)
					s.Color = ReadColor (stopColorAttribute.Value);
				var opacityAttribute = se.Attribute("stop-opacity");
				if (opacityAttribute != null)
					alpha = ReadNumber(opacityAttribute.Value);
				s.Color.Alpha = alpha;
				stops.Add (s);
			}
			stops.Sort ((x, y) => x.Offset.CompareTo (y.Offset));
		}