Skip to content

Commit a985dce

Browse files
committed
Fixed the NullReferenceException error
1 parent abc4e44 commit a985dce

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

MaterialDesignThemes.Wpf/PaletteHelper.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,27 @@ private static bool ReplaceEntry(object entryName, object newValue, ResourceDict
134134
{
135135
if (animate) //Fade animation is enabled
136136
{
137+
bool isfinished = false;
138+
var brush = new SolidColorBrush();
137139
ColorAnimation animation = new ColorAnimation()
138140
{
139141
From = (Color)parentDictionary[entryName],//The old color
140142
To = (Color)newValue, //The new color
141143
Duration = new Duration(new TimeSpan(0,0,0,0,DURATION_MS))
142144
};
143-
(parentDictionary[entryName] as Brush).BeginAnimation(SolidColorBrush.ColorProperty, animation); //Begin the animation
145+
animation.Completed += (s,e) =>
146+
{
147+
isfinished = true;
148+
};
149+
brush.BeginAnimation(SolidColorBrush.ColorProperty, animation); //Begin the animation
150+
System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
151+
dispatcherTimer.Tick += (sender, e) =>
152+
{
153+
if (!isfinished)
154+
parentDictionary[entryName] = brush;
155+
};
156+
dispatcherTimer.Interval = new TimeSpan(0,0,0,0,DURATION_MS / 60);//60 can be replaced with the animation frame rate.
157+
dispatcherTimer.Start();
144158

145159
}
146160
else

0 commit comments

Comments
 (0)