public void Refresh(string search = null) { var colors = new List <ColorItemViewModel>(); if (SystemParameters.HighContrast) { colors.Add(new ColorItemViewModel { Color = SystemColors.ActiveBorderBrush, Name = "ActiveBorderBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.ActiveCaptionBrush, Name = "ActiveCaptionBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.AppWorkspaceBrush, Name = "AppWorkspaceBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.ControlBrush, Name = "ControlBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.ControlDarkBrush, Name = "ControlDarkBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.ControlDarkDarkBrush, Name = "ControlDarkDarkBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.ControlLightBrush, Name = "ControlLightBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.ControlLightLightBrush, Name = "ControlLightLightBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.ControlTextBrush, Name = "ControlTextBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.DesktopBrush, Name = "DesktopBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.GradientActiveCaptionBrush, Name = "GradientActiveCaptionBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.GradientInactiveCaptionBrush, Name = "GradientInactiveCaptionBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.GrayTextBrush, Name = "GrayTextBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.HighlightBrush, Name = "HighlightBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.HighlightTextBrush, Name = "HighlightTextBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.HotTrackBrush, Name = "HotTrackBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.InactiveBorderBrush, Name = "InactiveBorderBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.InactiveCaptionBrush, Name = "InactiveCaptionBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.InactiveSelectionHighlightBrush, Name = "InactiveSelectionHighlightBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.InactiveSelectionHighlightTextBrush, Name = "InactiveSelectionHighlightTextBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.InfoBrush, Name = "InfoBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.InfoTextBrush, Name = "InfoTextBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.MenuBarBrush, Name = "MenuBarBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.MenuBrush, Name = "MenuBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.MenuHighlightBrush, Name = "MenuHighlightBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.MenuTextBrush, Name = "MenuTextBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.ScrollBarBrush, Name = "ScrollBarBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.WindowBrush, Name = "WindowBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.WindowFrameBrush, Name = "WindowFrameBrush" }); colors.Add(new ColorItemViewModel { Color = SystemColors.WindowTextBrush, Name = "WindowTextBrush" }); } else { foreach (var c in ImmersiveSystemColors.GetList().OrderBy(d => d.Key)) { if (!string.IsNullOrWhiteSpace(search)) { if (!c.Key.ToLower().Contains(search.ToLower())) { continue; } } // Exclude junk UI-specific colors that are stale anyway. if (c.Key.Contains("Boot")) { continue; } if (c.Key.Contains("Start")) { continue; } if (c.Key.Contains("Hardware")) { continue; } if (c.Key.Contains("Files")) { continue; } if (c.Key.Contains("Multitasking")) { continue; } var color = c.Value; // color.A = 255; // Very misleading to render on white otherwise! colors.Add(new ColorItemViewModel { Color = new SolidColorBrush(color), Opacity = $"{Math.Round(((float)color.A / 255) * 100, 0)}%", Name = c.Key }); } } Colors = colors; RaisePropertyChanged(nameof(Colors)); }
public static SolidColorBrush Parse(DependencyObject element, string value) { try { bool isLight = Options.GetSource(element) == Options.SourceKind.App ? SystemSettings.IsLightTheme : SystemSettings.IsSystemLightTheme; string lightOrDarkText = isLight ? "Light" : "Dark"; Dictionary <string, Dictionary <string, string> > fullMap = new Dictionary <string, Dictionary <string, string> >(); // Transparent // Theme=Transparent // Flyout:Theme=Transparent, HighContrast=Window foreach (var commaValue in value.Split(',')) { // Transparent // Theme=Transparent // Flyout:Theme=Transparent var segment = commaValue.Trim(); var scope = ""; if (segment.IndexOf(':') > -1) { var colonSplit = segment.Split(':'); scope = colonSplit[0]; segment = colonSplit[1]; } if (!fullMap.ContainsKey(scope)) { fullMap[scope] = new Dictionary <string, string>(); } // Transparent // Theme=Transparent var equalsSplit = segment.Split('='); var key = equalsSplit.Length == 1 ? "" : equalsSplit[0]; var color = equalsSplit.Length == 1 ? equalsSplit[0] : equalsSplit[1]; fullMap[scope][key] = color; } // Search for Refs in either the elementScope of deault map. var elementScope = Options.GetScope(element); var searchKey = ""; if (fullMap.ContainsKey(elementScope)) { if (fullMap[elementScope].ContainsKey("")) { searchKey = fullMap[elementScope][""]; } } else { if (fullMap[""].ContainsKey("")) { searchKey = fullMap[""][""]; } } if (searchKey != "") { if (FindReference(element, searchKey, out var outRef)) { return(outRef); } } // Pick the color considering theme. var map = fullMap.ContainsKey(elementScope) ? fullMap[elementScope] : fullMap[""]; string colorName; if (SystemParameters.HighContrast) { if (map.ContainsKey("")) { colorName = map[""]; } else if (map.ContainsKey("HighContrast")) { colorName = map["HighContrast"]; } else if (map.ContainsKey("Theme")) { colorName = map["Theme"].Replace("{Theme}", "Light"); } else if (map.ContainsKey("Light")) { colorName = map["Light"]; } else { throw new NotImplementedException($"BrushValueParser: '{value}'"); } } else { if (map.ContainsKey("")) { colorName = map[""]; } else if (map.ContainsKey("Theme")) { colorName = map["Theme"].Replace("{Theme}", isLight ? "Light" : "Dark"); } else if (map.ContainsKey("Light") && isLight) { colorName = map["Light"]; } else if (map.ContainsKey("Dark") && !isLight) { colorName = map["Dark"]; } else { throw new NotImplementedException($"BrushValueParser: '{value}'"); } } if (FindReference(element, colorName, out var reference)) { return(reference); } // Lookup the color Color ret; colorName = ParseOpacityFromColor(colorName, out var opacity); if (colorName[0] == '#') { ret = (Color)ColorConverter.ConvertFromString(colorName); } else if (!ImmersiveSystemColors.TryLookup($"Immersive{colorName}", out var color)) { var info = typeof(Colors).GetProperty(colorName, System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); if (info == null) { info = typeof(SystemColors).GetProperty(colorName + "Color", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); } ret = (Color)info.GetValue(null, null); } else { ret = color; } if (opacity > 0) { ret.A = (byte)(opacity * 255); } return(new SolidColorBrush(ret)); } catch (Exception ex) { throw new Exception($"BrushValueParser Error: '{value}'", ex); } }
public Color LookupThemeColor(string color) => ImmersiveSystemColors.Lookup(color);