public static IExtendedTheme GetExtendedTheme(this ResourceDictionary resourceDictionary) { if (resourceDictionary == null) { throw new ArgumentNullException(nameof(resourceDictionary)); } if (resourceDictionary[CurrentThemeKey] is IExtendedTheme theme) { return(theme); } Color secondaryMid = GetColor(resourceDictionary, "SecondaryHueMidBrush", "SecondaryHueMidBrush"); Color secondaryMidForeground = GetColor(resourceDictionary, "SecondaryHueMidForegroundBrush", "SecondaryHueMidForegroundBrush"); if (!TryGetColor(resourceDictionary, "SecondaryHueLightBrush", out Color secondaryLight)) { secondaryLight = secondaryMid.Lighten(); } if (!TryGetColor(resourceDictionary, "SecondaryHueLightForegroundBrush", out Color secondaryLightForeground)) { secondaryLightForeground = secondaryLight.ContrastingForegroundColor(); } if (!TryGetColor(resourceDictionary, "SecondaryHueDarkBrush", out Color secondaryDark)) { secondaryDark = secondaryMid.Darken(); } if (!TryGetColor(resourceDictionary, "SecondaryHueDarkForegroundBrush", out Color secondaryDarkForeground)) { secondaryDarkForeground = secondaryDark.ContrastingForegroundColor(); } ExtendedTheme newTheme = new ExtendedTheme { PrimaryLight = new ColorPair(GetColor(resourceDictionary, "PrimaryHueLightBrush"), GetColor(resourceDictionary, "PrimaryHueLightForegroundBrush")), PrimaryMid = new ColorPair(GetColor(resourceDictionary, "PrimaryHueMidBrush"), GetColor(resourceDictionary, "PrimaryHueMidForegroundBrush")), PrimaryDark = new ColorPair(GetColor(resourceDictionary, "PrimaryHueDarkBrush"), GetColor(resourceDictionary, "PrimaryHueDarkForegroundBrush")), SecondaryLight = new ColorPair(secondaryLight, secondaryLightForeground), SecondaryMid = new ColorPair(secondaryMid, secondaryMidForeground), SecondaryDark = new ColorPair(secondaryDark, secondaryDarkForeground), ValidationError = GetColor(resourceDictionary, "ValidationErrorBrush") }; GetColorProperties(newTheme.GetType(), false, true) .ForEach(property => property.SetValue(newTheme, GetColor(resourceDictionary, GetKey(property)))); return(newTheme); }
public static ExtendedTheme Create(IExtendedBaseTheme baseTheme, Color primary, Color accent) { if (baseTheme == null) { throw new ArgumentNullException(nameof(baseTheme)); } ExtendedTheme theme = new ExtendedTheme(); theme.SetBaseTheme(baseTheme); theme.SetPrimaryColor(primary); theme.SetSecondaryColor(accent); return(theme); }