Styles.cs 2.86 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
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;
14
        static List<SolidColorBrush> randomColorsDark;
15 16 17 18
        public static List<SolidColorBrush> AreaColors;
        static Styles()
        {

19
            ResourceDictionary resourceDictionary = new ResourceDictionary() { Source = new Uri("pack://application:,,,/FLY.ControlLibrary;component/Themes/Colors2.xaml") };
20 21 22

            AreaColors = new List<SolidColorBrush>();
            for (int i = 0; i < 5; i++)
23
                AreaColors.Add(resourceDictionary[$"Brushes.Area{i}"] as SolidColorBrush);
24 25

            randomColors = new List<SolidColorBrush>();
26
            randomColors.AddRange(resourceDictionary["Brushes.Random"] as IEnumerable<SolidColorBrush>);
27

28 29
            randomColorsDark = new List<SolidColorBrush>();
            randomColorsDark.AddRange(resourceDictionary["Brushes.Random.Dark"] as IEnumerable<SolidColorBrush>);
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
            //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>
55
        public static Brush GetForeground(int index, bool isDark = false)
56
        {
57 58 59 60
            if(isDark)
                return randomColorsDark.ElementAt(index % randomColorsDark.Count());
            else
                return randomColors.ElementAt(index % randomColors.Count());
61 62 63
        }
    }
}