public static uint AddIndexedColor(this Stylesheet stylesheet, System.Windows.Media.Color color) { uint fillId = stylesheet.AddFill(color); string hexColor = "00" + TranslateColor(color); if (stylesheet.Colors == null) { stylesheet.Colors = new Colors(); } if (stylesheet.Colors.IndexedColors == null) { stylesheet.Colors.IndexedColors = new IndexedColors(); } var indexedColor = stylesheet.Colors.IndexedColors.FirstOrDefault(x => string.Equals(((RgbColor)x).Rgb.Value, hexColor)); if (indexedColor == null) { stylesheet.Colors.IndexedColors.Append( new RgbColor() { Rgb = hexColor }); //var elementAt = stylesheet.Colors.IndexedColors.ElementAt(stylesheet.Colors.IndexedColors.Count() - 10); //elementAt.Remove(); } return(fillId); }
/// <summary> /// Gets the or create fill. /// </summary> /// <param name="index">The index.</param> /// <param name="source">The source.</param> /// <param name="target">The target.</param> /// <returns></returns> private static uint GetOrCreateFill(uint index, Stylesheet source, Stylesheet target) { var child = SafeIndex <Fills, Fill>(source.Fills, (int)index); if (child == null) { return(0); } uint id = 0; if (target.TryMatchFill(child, out id)) { return(id); } return(target.AddFill(child)); }