I am trying to make a slider control in WPF. So I have an ellipse to change its color to green when it's slided. I tried this code using Storyboard.TargetProperty=Fill
<ColorAnimation Storyboard.TargetName="ball" Storyboard.TargetProperty="Fill.Color" From="Red" To="LightGreen" Duration="0:0:0.3"/>
But it didn't work. I did some research and realized that it needs to be Fill.Color. Normally Ellipse has a Fill property to be filled. Why does it need the Color extension?
Fillis a Brush type not a Color type. There are default converters in place that allow you to use simplified notations such asFill="Red"in your XAML, but all that means is that you are settingFillto aSolidColorBrushwith a color ofRedA
ColorAnimationas per its name will animate between Colors not Brushes, so you need to get to the Color property of theFill(in your case fill is a SolidColorBrush which has aColorproperty).As an additional example, if you were to set your
Fillto a more complicated Brush such as a LinearGradientBrush, you can still manipulate the gradient in anColorAnimationbut the syntax becomes a lot more complex: