Skip to content

Commit cfd62e8

Browse files
committed
Small fix
1 parent 26950a7 commit cfd62e8

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

MaterialDesignThemes.Wpf/PaletteHelper.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,23 +126,22 @@ public void ReplaceAccentColor(string name)
126126
private static bool ReplaceEntry(object entryName, object newValue, ResourceDictionary parentDictionary = null, bool animate = true)
127127
{
128128
const int DURATION_MS = 500; //Change the value if needed
129-
129+
int ANIMATION_FPS = 60;
130130
if (parentDictionary == null)
131131
parentDictionary = Application.Current.Resources;
132132

133133
if (parentDictionary.Contains(entryName))
134134
{
135-
if (animate) //Fade animation is enabled
135+
if (animate & parentDictionary[entryName] != null ) //Fade animation is enabled and value is not null.
136136
{
137137
try
138138
{
139139
ColorAnimation animation = new ColorAnimation()
140140
{
141-
From = (Color)parentDictionary[entryName],//The old color
142-
To = (Color)newValue, //The new color
141+
From = ((SolidColorBrush)parentDictionary[entryName]).Color,//The old color
142+
To = ((SolidColorBrush)newValue).Color, //The new color
143143
Duration = new Duration(new TimeSpan(0,0,0,0,DURATION_MS)) //Set the duration
144144
};
145-
parentDictionary[entryName] = parentDictionary[entryName] == null ? new SolidColorBrush() : parentDictionary[entryName]; //Set the resource as a new SolidColorBrush if null.
146145
(parentDictionary[entryName] as SolidColorBrush).BeginAnimation(SolidColorBrush.ColorProperty, animation); //Begin the animation
147146
}
148147
catch
@@ -161,5 +160,5 @@ private static bool ReplaceEntry(object entryName, object newValue, ResourceDict
161160

162161
return false;
163162
}
164-
}
163+
}
165164
}

0 commit comments

Comments
 (0)