Skip to content

Commit e9c5d4e

Browse files
committed
Simplify code and reduced complexity
Found out the problem was just parentDictionary[entryName] being null. No need for large code
1 parent 482f574 commit e9c5d4e

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

MaterialDesignThemes.Wpf/PaletteHelper.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public void ReplacePrimaryColor(Swatch swatch, bool mahapps = false)
4848

4949
foreach (var color in swatch.PrimaryHues)
5050
{
51-
ReplaceEntry(color.Name, color.Color);
52-
ReplaceEntry(color.Name + "Foreground", color.Foreground);
51+
ReplaceEntry(color.Name, color.Color, null, false);
52+
ReplaceEntry(color.Name + "Foreground", color.Foreground, null, false);
5353
}
5454

5555
ReplaceEntry("PrimaryHueLightBrush", new SolidColorBrush(light.Color));
@@ -95,8 +95,8 @@ public void ReplaceAccentColor(Swatch swatch)
9595

9696
foreach (var color in swatch.AccentHues)
9797
{
98-
ReplaceEntry(color.Name, color.Color);
99-
ReplaceEntry(color.Name + "Foreground", color.Foreground);
98+
ReplaceEntry(color.Name, color.Color,null, false);
99+
ReplaceEntry(color.Name + "Foreground", color.Foreground, null, false);
100100
}
101101

102102
ReplaceEntry("SecondaryAccentBrush", new SolidColorBrush(swatch.AccentExemplarHue.Color));
@@ -134,29 +134,17 @@ private static bool ReplaceEntry(object entryName, object newValue, ResourceDict
134134
{
135135
if (animate) //Fade animation is enabled
136136
{
137-
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
138-
var brush = new SolidColorBrush();
139137
ColorAnimation animation = new ColorAnimation()
140138
{
141139
From = (Color)parentDictionary[entryName],//The old color
142140
To = (Color)newValue, //The new color
143141
Duration = new Duration(new TimeSpan(0,0,0,0,DURATION_MS))
144142
};
145-
animation.Completed += (s,e) =>
146-
{
147-
dispatcherTimer.Stop();
148-
};
149-
brush.BeginAnimation(SolidColorBrush.ColorProperty, animation); //Begin the animation
150-
151-
dispatcherTimer.Tick += (sender, e) => parentDictionary[entryName] = brush;
152-
dispatcherTimer.Interval = new TimeSpan(0,0,0,0,DURATION_MS / 60);//60 can be replaced with the animation frame rate.
153-
dispatcherTimer.Start();
154-
143+
parentDictionary[entryName] = new SolidColorBrush();
144+
(parentDictionary[entryName] as SolidColorBrush).BeginAnimation(SolidColorBrush.ColorProperty, animation); //Begin the animation
155145
}
156146
else
157-
{
158147
parentDictionary[entryName] = newValue;
159-
}
160148
return true;
161149
}
162150
foreach (var dictionary in parentDictionary.MergedDictionaries)

0 commit comments

Comments
 (0)