private static void ApplyAccent(Swatch swatch)
 {
     paletteHelper.ReplacePrimaryColor(swatch,true);
     paletteHelper.ReplaceAccentColor(swatch);
     Settings.Default.AccentTheme = swatch.Name;
     Settings.Default.Save();
 }
 public Palette(Swatch primarySwatch, Swatch accentSwatch, int primaryLightHueIndex, int primaryMidHueIndex, int primaryDarkHueIndex, int accentHueIndex)
 {
     PrimarySwatch = primarySwatch;
     AccentSwatch = accentSwatch;
     PrimaryLightHueIndex = primaryLightHueIndex;
     PrimaryMidHueIndex = primaryMidHueIndex;
     PrimaryDarkHueIndex = primaryDarkHueIndex;
     AccentHueIndex = accentHueIndex;
 }
        public virtual void ReplaceAccentColor(Swatch swatch)
        {
            if (swatch == null) throw new ArgumentNullException(nameof(swatch));

            foreach (var color in swatch.AccentHues)
            {
                ReplaceEntry(color.Name, color.Color);
                ReplaceEntry(color.Name + "Foreground", color.Foreground);
            }

            ReplaceEntry("SecondaryAccentBrush", new SolidColorBrush(swatch.AccentExemplarHue.Color));
            ReplaceEntry("SecondaryAccentForegroundBrush", new SolidColorBrush(swatch.AccentExemplarHue.Foreground));
        }
        /// <summary>
        /// Replaces the primary colour, selecting a balanced set of hues for the light, mid and dark hues.
        /// </summary>
        /// <param name="swatch"></param>
        public virtual void ReplacePrimaryColor(Swatch swatch)
        {
            if (swatch == null) throw new ArgumentNullException(nameof(swatch));

            var palette = QueryPalette();

            var list = swatch.PrimaryHues.ToList();
            var light = list[palette.PrimaryLightHueIndex];
            var mid = list[palette.PrimaryMidHueIndex];
            var dark = list[palette.PrimaryDarkHueIndex];

            ReplacePrimaryColor(swatch, light, mid, dark, list);
        }      
        public void ReplaceAccentColor(Swatch swatch)
        {
            if (swatch == null) throw new ArgumentNullException(nameof(swatch));

            ResourceDictionary oldColorResourceDictionary;
            if (!TryFindSwatchDictionary(Application.Current.Resources, "SecondaryAccentBrush", out oldColorResourceDictionary))
                throw new ApplicationException("Unable to find accent color definition in Application resources.");

            var newColorResourceDictionary = new ResourceDictionary
            {
                {"SecondaryAccentBrush", new SolidColorBrush(swatch.AccentExemplarHue.Color)},
                {"SecondaryAccentForegroundBrush", new SolidColorBrush(swatch.AccentExemplarHue.Foreground)},
            };

            Application.Current.Resources.MergedDictionaries.Remove(oldColorResourceDictionary);
            Application.Current.Resources.MergedDictionaries.Add(newColorResourceDictionary);
        }
        public void ReplacePrimaryColor(Swatch swatch)
        {
            if (swatch == null) throw new ArgumentNullException(nameof(swatch));

            ResourceDictionary oldColorResourceDictionary;
            if (!TryFindSwatchDictionary(Application.Current.Resources, "PrimaryHueMidBrush", out oldColorResourceDictionary))
                throw new ApplicationException("Unable to find primary color definition in Application resources.");

            var list = swatch.PrimaryHues.ToList();
            var light = list[2];
            var mid = swatch.ExemplarHue;
            var dark = list[7];

            //TODO reuse some of the dupes, freeze.

            var newColorResourceDictionary = new ResourceDictionary
            {
                {"PrimaryHueLightBrush", new SolidColorBrush(light.Color)},
                {"PrimaryHueLightForegroundBrush", new SolidColorBrush(light.Foreground)},
                {"PrimaryHueMidBrush", new SolidColorBrush(mid.Color)},
                {"PrimaryHueMidForegroundBrush", new SolidColorBrush(mid.Foreground)},
                {"PrimaryHueDarkBrush", new SolidColorBrush(dark.Color)},
                {"PrimaryHueDarkForegroundBrush", new SolidColorBrush(dark.Foreground)}
            };

            if (oldColorResourceDictionary.Keys.OfType<string>().Contains("HighlightBrush"))
            {
                newColorResourceDictionary.Add("HighlightBrush", new SolidColorBrush(dark.Color));
                newColorResourceDictionary.Add("AccentColorBrush", new SolidColorBrush(list[5].Color));
                newColorResourceDictionary.Add("AccentColorBrush2", new SolidColorBrush(list[4].Color));
                newColorResourceDictionary.Add("AccentColorBrush3", new SolidColorBrush(list[3].Color));
                newColorResourceDictionary.Add("AccentColorBrush4", new SolidColorBrush(list[2].Color));
                newColorResourceDictionary.Add("WindowTitleColorBrush", new SolidColorBrush(dark.Color));
                newColorResourceDictionary.Add("AccentSelectedColorBrush", new SolidColorBrush(list[5].Foreground));
                newColorResourceDictionary.Add("ProgressBrush", new LinearGradientBrush(dark.Color, list[3].Color, 90.0));
                newColorResourceDictionary.Add("CheckmarkFill", new SolidColorBrush(list[5].Color));
                newColorResourceDictionary.Add("RightArrowFill", new SolidColorBrush(list[5].Color));
                newColorResourceDictionary.Add("IdealForegroundColorBrush", new SolidColorBrush(list[5].Foreground));
                newColorResourceDictionary.Add("IdealForegroundDisabledBrush", new SolidColorBrush(dark.Color) { Opacity = .4 });
            }

            Application.Current.Resources.MergedDictionaries.Remove(oldColorResourceDictionary);
            Application.Current.Resources.MergedDictionaries.Add(newColorResourceDictionary);
        }
        public void ReplacePrimaryColor(Swatch swatch, bool mahapps = false)
        {
            if (swatch == null) throw new ArgumentNullException(nameof(swatch));

            var list = swatch.PrimaryHues.ToList();
            var light = list[2];
            var mid = swatch.ExemplarHue;
            var dark = list[7];

            foreach (var color in swatch.PrimaryHues)
            {
                ReplaceEntry(color.Name, color.Color);
                ReplaceEntry(color.Name + "Foreground", color.Foreground);
            }

            ReplaceEntry("PrimaryHueLightBrush", new SolidColorBrush(light.Color));
            ReplaceEntry("PrimaryHueLightForegroundBrush", new SolidColorBrush(light.Foreground));
            ReplaceEntry("PrimaryHueMidBrush", new SolidColorBrush(mid.Color));
            ReplaceEntry("PrimaryHueMidForegroundBrush", new SolidColorBrush(mid.Foreground));
            ReplaceEntry("PrimaryHueDarkBrush", new SolidColorBrush(dark.Color));
            ReplaceEntry("PrimaryHueDarkForegroundBrush", new SolidColorBrush(dark.Foreground));

            if (mahapps)
            {
                ReplaceEntry("HighlightBrush", new SolidColorBrush(dark.Color));
                ReplaceEntry("AccentColorBrush", new SolidColorBrush(list[5].Color));
                ReplaceEntry("AccentColorBrush2", new SolidColorBrush(list[4].Color));
                ReplaceEntry("AccentColorBrush3", new SolidColorBrush(list[3].Color));
                ReplaceEntry("AccentColorBrush4", new SolidColorBrush(list[2].Color));
                ReplaceEntry("WindowTitleColorBrush", new SolidColorBrush(dark.Color));
                ReplaceEntry("AccentSelectedColorBrush", new SolidColorBrush(list[5].Foreground));
                ReplaceEntry("ProgressBrush", new LinearGradientBrush(dark.Color, list[3].Color, 90.0));
                ReplaceEntry("CheckmarkFill", new SolidColorBrush(list[5].Color));
                ReplaceEntry("RightArrowFill", new SolidColorBrush(list[5].Color));
                ReplaceEntry("IdealForegroundColorBrush", new SolidColorBrush(list[5].Foreground));
                ReplaceEntry("IdealForegroundDisabledBrush", new SolidColorBrush(dark.Color) { Opacity = .4 });
            }
        }
 private void ApplyAccent(Swatch swatch)
 {
     new PaletteHelper().ReplaceAccentColor(swatch);
     Settings.Default.AccentColorUri = $"pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.{swatch.Name}.xaml";
     Settings.Default.Save();
 }
 private static void ApplyPrimary(Swatch swatch)
 {
     new PaletteHelper().ReplacePrimaryColor(swatch);
 }
Exemplo n.º 10
0
 private static void ApplyAccent(Swatch swatch)
 {
     new PaletteHelper().ReplaceAccentColor(swatch);
 }
        public virtual void ReplaceAccentColor(Swatch swatch)
        {
            if (swatch == null) throw new ArgumentNullException(nameof(swatch));

            var palette = QueryPalette();

            foreach (var color in swatch.AccentHues)
            {
                ReplaceEntry(color.Name, color.Color);
                ReplaceEntry(color.Name + "Foreground", color.Foreground);
            }

            var hue = swatch.AccentHues.ElementAt(palette.AccentHueIndex);

            ReplaceEntry("SecondaryAccentBrush", new SolidColorBrush(hue.Color));
            ReplaceEntry("SecondaryAccentForegroundBrush", new SolidColorBrush(hue.Foreground));
        }
 private static int GetHueIndex(Swatch swatch, Color color, bool isAccent)
 {
     var x = (isAccent ? swatch.AccentHues : swatch.PrimaryHues).Select((h, i) => new {h, i})
         .FirstOrDefault(a => a.h.Color == color);
     if (x == null)
         throw new InvalidOperationException($"Color {color} not found in swatch {swatch.Name}.");
     return x.i;
 }
        private static void ReplacePrimaryColor(Swatch swatch, Hue light, Hue mid, Hue dark, IList<Hue> allHues)
        {
            foreach (var color in swatch.PrimaryHues)
            {
                ReplaceEntry(color.Name, color.Color);
                ReplaceEntry(color.Name + "Foreground", color.Foreground);
            }

            ReplaceEntry("PrimaryHueLightBrush", new SolidColorBrush(light.Color));
            ReplaceEntry("PrimaryHueLightForegroundBrush", new SolidColorBrush(light.Foreground));
            ReplaceEntry("PrimaryHueMidBrush", new SolidColorBrush(mid.Color));
            ReplaceEntry("PrimaryHueMidForegroundBrush", new SolidColorBrush(mid.Foreground));
            ReplaceEntry("PrimaryHueDarkBrush", new SolidColorBrush(dark.Color));
            ReplaceEntry("PrimaryHueDarkForegroundBrush", new SolidColorBrush(dark.Foreground));

            //mahapps brushes            
            ReplaceEntry("HighlightBrush", new SolidColorBrush(dark.Color));
            ReplaceEntry("AccentColorBrush", new SolidColorBrush(dark.Color));
            ReplaceEntry("AccentColorBrush2", new SolidColorBrush(mid.Color));
            ReplaceEntry("AccentColorBrush3", new SolidColorBrush(light.Color));
            ReplaceEntry("AccentColorBrush4", new SolidColorBrush(light.Color) { Opacity = .82 });
            ReplaceEntry("WindowTitleColorBrush", new SolidColorBrush(dark.Color));
            ReplaceEntry("AccentSelectedColorBrush", new SolidColorBrush(dark.Foreground));
            ReplaceEntry("ProgressBrush", new LinearGradientBrush(dark.Color, mid.Color, 90.0));
            ReplaceEntry("CheckmarkFill", new SolidColorBrush(dark.Color));
            ReplaceEntry("RightArrowFill", new SolidColorBrush(dark.Color));
            ReplaceEntry("IdealForegroundColorBrush", new SolidColorBrush(dark.Foreground));
            ReplaceEntry("IdealForegroundDisabledBrush", new SolidColorBrush(dark.Color) { Opacity = .4 });
        }