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

            ResourceDictionary resourceDictionary = new ResourceDictionary() { Source = new Uri("pack://application:,,,/FLY.ControlLibrary;component/Themes/Colors.xaml") };

            AreaColors = new List<SolidColorBrush>();
            for (int i = 0; i < 5; i++)
22
                AreaColors.Add(resourceDictionary[$"AreaColors{i}"] as SolidColorBrush);
23 24 25 26 27 28 29 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 55 56 57 58 59 60 61 62 63 64 65

            randomColors = new List<SolidColorBrush>();
            randomColors.AddRange(resourceDictionary["RandomColors"] 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)
        {
            //XamlReader.Loadnew FileStream(@"C:\Users\wppcn\source\repos\网易云\网易云\Resourece\SvgImgResource.xaml", FileMode.Open)) as ResourceDictionary;
            //string assembleName = typeof(Styles).Assembly.GetName().Name;//本程序集名
            //Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"{assembleName}.Themes.Styles.xaml");//获取嵌入资源生成流,XMLPATH为嵌入资源路径,资源名称访问路径为:assemblename.文件夹名.资源名
            //XamlReader.Load(stream) as 

            //IEnumerable<SolidColorBrush> randomColors = App.Current.FindResource("RandomColors") as IEnumerable<SolidColorBrush>;


            return randomColors.ElementAt(index % randomColors.Count());
        }
    }
}