private void LoadColors(string filterBy) { var themeColors = new List <ThemeColor>(); var type = typeof(EnvironmentColors); IEnumerable <PropertyInfo> properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var property in properties) { var themeColor = new ThemeColor { ColorKey = property.Name }; var k = property.GetValue(this, null) as ComponentResourceKey; try { var brush = (Brush)FindResource(k); if (brush is SolidColorBrush) { var solidBrush = brush as SolidColorBrush; Color color = solidBrush.Color; if (string.IsNullOrWhiteSpace(filterBy) || String.CompareOrdinal(String.Format("{0},{1},{2}", color.R.ToString(CultureInfo.InvariantCulture), color.G.ToString(CultureInfo.InvariantCulture), color.B.ToString(CultureInfo.InvariantCulture)), filterBy) == 0) { themeColor.ComponentResourceKey = k; themeColor.Color = solidBrush; themeColor.RGB = string.Format("{0},{1},{2},{3}", color.A.ToString("X2"), color.R.ToString("X2"), color.G.ToString("X2"), color.B.ToString("X2")); themeColor.FontColor = GetLabelFontColor(Color.FromArgb(color.A, color.R, color.G, color.B)); themeColors.Add(themeColor); } } } catch (Exception) { } } ListView.ItemsSource = themeColors; }
private void LoadColors(string filterBy) { var themeColors = new List<ThemeColor>(); var type = typeof (EnvironmentColors); IEnumerable<PropertyInfo> properties = type.GetProperties(BindingFlags.Public | BindingFlags.Static); foreach (var property in properties) { var themeColor = new ThemeColor {ColorKey = property.Name}; var k = property.GetValue(this, null) as ComponentResourceKey; try { var brush = (Brush)FindResource(k); if (brush is SolidColorBrush) { var solidBrush = brush as SolidColorBrush; Color color = solidBrush.Color; if (string.IsNullOrWhiteSpace(filterBy) || String.CompareOrdinal(String.Format("{0},{1},{2}", color.R.ToString(CultureInfo.InvariantCulture), color.G.ToString(CultureInfo.InvariantCulture), color.B.ToString(CultureInfo.InvariantCulture)), filterBy) == 0) { themeColor.ComponentResourceKey = k; themeColor.Color = solidBrush; themeColor.RGB = string.Format("{0},{1},{2},{3}",color.A.ToString("X2"), color.R.ToString("X2"), color.G.ToString("X2"), color.B.ToString("X2")); themeColor.FontColor = GetLabelFontColor(Color.FromArgb(color.A, color.R, color.G, color.B)); themeColors.Add(themeColor); } } } catch (Exception) { } } ListView.ItemsSource = themeColors; }