Пример #1
0
        /// <summary>
        /// Загружает ClassicColors цвета, как базовые для разных цветовых тем
        /// </summary>
        /// <param name="groupRes"></param>
        /// <param name="assemblyName"></param>
        /// <returns></returns>
        private Swatch GetClassicColorsList(IGrouping <string, SelBaml>[] groupRes, string assemblyName)
        {
            string name = "ClassicColors";
            var    res  = GetResourceDictionaryBaml(name, groupRes, assemblyName);

            if (res == null)
            {
                throw new Exception("ClassicColors.xaml not found");
            }

            if (res.Count == 0)
            {
                throw new Exception("ClassicColors.xaml is empty");
            }

            if (res.Count > 0)
            {
                Dictionary <string, Color> colors = GetColors(res);

                Swatch swatch = new Swatch(name);
                foreach (KeyValuePair <string, Color> pair in colors)
                {
                    swatch.AddHue(new Hue(pair.Key, pair.Value));
                }

                return(swatch);
            }

            return(null);
        }
Пример #2
0
        /// <summary>
        /// Создает наборы цветов и проверят их с класическими цветами
        /// </summary>
        /// <param name="classicColors"></param>
        /// <param name="groupRes"></param>
        /// <param name="assemblyName"></param>
        /// <returns></returns>
        private List <Swatch> GetSwatches(Swatch classicColors, IGrouping <string, SelBaml>[] groupRes, string assemblyName)
        {
            List <Swatch> swatches = new List <Swatch>();

            foreach (IEnumerable <SelBaml> grp in groupRes)
            {
                SelBaml selBaml = grp.First();
                var     name    = selBaml.match.Groups["fileName"].Value;

                if (!string.Equals(name, classicColors.Name, StringComparison.CurrentCultureIgnoreCase))
                {
                    var res = GetResourceDictionaryBaml(name, groupRes, assemblyName);

                    if (res == null)
                    {
                        throw new Exception(name + " not found");
                    }

                    if (res.Count == 0)
                    {
                        continue;
                        // throw new Exception(name + " is empty");
                    }

                    if (res.Count > 0)
                    {
                        Dictionary <string, Color> colors = GetColors(res);

                        Swatch swatch = new Swatch(name);
                        swatches.Add(swatch);
                        foreach (Hue hue in classicColors.Hues)
                        {
                            if (!colors.ContainsKey(hue.Name))
                            {
                                swatch.AddHue(new Hue(hue.Name, hue.Color));
                            }
                            else
                            {
                                swatch.AddHue(new Hue(hue.Name, colors[hue.Name]));
                            }
                        }
                    }
                }
            }

            return(swatches);
        }