Exemple #1
0
 private static double GetTemp2(HSLColor hslColor)
 {
     double temp2;
     if (hslColor._luminosity < 0.5)  //<=??
         temp2 = hslColor._luminosity * (1.0 + hslColor._saturation);
     else
         temp2 = hslColor._luminosity + hslColor._saturation - (hslColor._luminosity * hslColor._saturation);
     return temp2;
 }
        public XDocument Update(string baseColourHex)
        {
            baseColourHex = baseColourHex.Trim('#');
            if (baseColourHex.Length == 8)
                baseColourHex = baseColourHex.Substring(2);

            var output = new XDocument(_document);

            var baseColour = new HSLColor(baseColourHex);
            var dictionary = output.Element(XamlPresentationNamespace + "ResourceDictionary");

            var themeResources = (XElement)dictionary.FirstNode;
            foreach (var x in themeResources.Elements())
            {
                var brushKey = x.Attribute(XamlRootNamespace + "Key");
                if (brushKey == null)
                    continue;

                var key = brushKey.Value;
                if (key == "HighContrast")
                    continue;

                foreach (var brush in Brushes[key])
                {
                    var y = x.Elements().FirstOrDefault(i => i.Attribute(XamlRootNamespace + "Key").Value == brush.Key);
                    if (y == null)
                        continue;

                    var attribute = y.Attribute("Color");
                    if (attribute == null)
                        continue;

                    var newColour = new HSLColor(baseColour.Hue, baseColour.Saturation, baseColour.Luminosity + brush.Value);
                    attribute.SetValue(newColour.ToHex());
                }
            }

            return output;
        }