1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
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());
}
}
}