using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Media; namespace FLY.ControlLibrary.Themes { public static class Styles { static List<SolidColorBrush> randomColors; static List<SolidColorBrush> randomColorsDark; public static List<SolidColorBrush> AreaColors; static Styles() { ResourceDictionary resourceDictionary = new ResourceDictionary() { Source = new Uri("pack://application:,,,/FLY.ControlLibrary;component/Themes/Colors2.xaml") }; AreaColors = new List<SolidColorBrush>(); for (int i = 0; i < 5; i++) AreaColors.Add(resourceDictionary[$"Brushes.Area{i}"] as SolidColorBrush); randomColors = new List<SolidColorBrush>(); randomColors.AddRange(resourceDictionary["Brushes.Random"] as IEnumerable<SolidColorBrush>); randomColorsDark = new List<SolidColorBrush>(); randomColorsDark.AddRange(resourceDictionary["Brushes.Random.Dark"] as IEnumerable<SolidColorBrush>); //randomColors = new SolidColorBrush[] { // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2195f2")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#f34336")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fec007")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#607d8a")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#e81e63")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4cae50")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#3f51b4")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ccdb39")) //}; //AreaColors = new SolidColorBrush[] { // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#f34336")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#fec007")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4cae50")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("#2195f2")), // new SolidColorBrush((Color)ColorConverter.ConvertFromString("DarkSlateBlue")) //}; } /// <summary> /// 获取随机颜色 /// </summary> /// <param name="index"></param> /// <returns></returns> public static Brush GetForeground(int index, bool isDark = false) { if(isDark) return randomColorsDark.ElementAt(index % randomColorsDark.Count()); else return randomColors.ElementAt(index % randomColors.Count()); } } }