private static ApplicationColorSet fromResourceDictionary(ResourceDictionary dict) { if (dict == null) { return(null); } ApplicationColorSet colors = new ApplicationColorSet(); colors.AccentColor = (Color)dict[ACCENT_COLOR]; colors.AccentTextColor = (Color)dict[ACCENT_TEXT_COLOR]; colors.BackgroundEndGradientColor = (Color)dict[BACKGROUND_END_GRADIENT_STOP_COLOR]; colors.BackgroundStartGradientColor = (Color)dict[BACKGROUND_START_GRADIENT_STOP_COLOR]; colors.BackgroundTextColor = (Color)dict[BACKGROUND_TEXT_COLOR]; colors.SelectionColor = (Color)dict[SELECTION_COLOR]; colors.SelectionOutlineColor = (Color)dict[SELECTION_OUTLINE_COLOR]; return(colors); }
public static void ApplyColorProperty(ApplicationColorSet applicationColorSet, Color Color, ThemeColorProperty Property) { if (applicationColorSet == null) { return; } switch (Property) { case ThemeColorProperty.BackgroundEndGradientColor: applicationColorSet.BackgroundEndGradientColor = Color; break; case ThemeColorProperty.BackgroundStartGradientColor: applicationColorSet.BackgroundStartGradientColor = Color; break; case ThemeColorProperty.AccentColor: applicationColorSet.AccentColor = Color; break; case ThemeColorProperty.AccentTextColor: applicationColorSet.AccentTextColor = Color; break; case ThemeColorProperty.BackgroundTextColor: applicationColorSet.BackgroundTextColor = Color; break; case ThemeColorProperty.SelectionColor: applicationColorSet.SelectionColor = Color; break; case ThemeColorProperty.SelectionOutlineColor: applicationColorSet.SelectionOutlineColor = Color; break; } }
public string GetColorXaml() { if (string.IsNullOrEmpty(applicationColorsFileContents)) { return(null); } XDocument xDoc = XDocument.Parse(applicationColorsFileContents); ApplicationColorSet applicationColorSet = ApplicationColorSet; if (applicationColorSet != null) { var firstNode = xDoc.Nodes().FirstOrDefault(n => n is XElement); foreach (XElement resource in (firstNode as XElement).Elements()) { string resourceKey = null; foreach (XAttribute attrib in resource.Attributes()) { if (attrib.Name != null && attrib.Name.LocalName == "Key") { resourceKey = attrib.Value; break; } } if (string.IsNullOrEmpty(resourceKey)) { continue; } switch (resourceKey) { case ACCENT_COLOR: resource.SetValue(applicationColorSet.AccentColor.ToString()); break; case ACCENT_TEXT_COLOR: resource.SetValue(applicationColorSet.AccentTextColor.ToString()); break; case BACKGROUND_END_GRADIENT_STOP_COLOR: resource.SetValue(applicationColorSet.BackgroundEndGradientColor.ToString()); break; case BACKGROUND_START_GRADIENT_STOP_COLOR: resource.SetValue(applicationColorSet.BackgroundStartGradientColor.ToString()); break; case BACKGROUND_TEXT_COLOR: resource.SetValue(applicationColorSet.BackgroundTextColor.ToString()); break; case SELECTION_COLOR: resource.SetValue(applicationColorSet.SelectionColor.ToString()); break; case SELECTION_OUTLINE_COLOR: resource.SetValue(applicationColorSet.SelectionOutlineColor.ToString()); break; } } } return(xDoc.ToString(SaveOptions.OmitDuplicateNamespaces)); }