0

How can you set the animation of "EndPointProperty" or "StartPointProperty" to animate LinearGradientBrush?

I have this code in xaml:

<Rectangle x:Name="itemRefl"  >
 <Rectangle.Fill>
  <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
    <GradientStop Offset="0"/>
    <GradientStop Color="White" Offset="0.5"/>
    <GradientStop Offset="1"/>
  </LinearGradientBrush>
 </Rectangle.Fill>
</Rectangle>

And my code for animation is this but not work without errors. How I can animate this property correctly?

Storyboard story1 = new Storyboard();
PointAnimation endPointAnim = new PointAnimation()
{
   EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut },
   From = new Point( 0.0, -0.26),
   To = new Point(0.0, 0.26),
   Duration = new Duration(TimeSpan.FromMilliseconds(500))

};
Storyboard.SetTargetProperty(endPointAnim, new PropertyPath(LinearGradientBrush.EndPointProperty));
story1.Children.Add(endPointAnim);
myelement.BeginStoryboard(story1);

Thank you

Ares
  • 3
  • 2

1 Answers1

0

Run the animation directly on the LinearGradientBrush:

itemRefl.Fill.BeginAnimation(LinearGradientBrush.EndPointProperty, endPointAnim);
Clemens
  • 123,504
  • 12
  • 155
  • 268
  • This work, thank you. The final code is: `PointAnimation endPointAnim = new PointAnimation() { EasingFunction = new SineEase { EasingMode = EasingMode.EaseInOut }, From = new Point( 0.0, -0.26), To = new Point(0.0, 0.26), Duration = new Duration(TimeSpan.FromMilliseconds(500)) }; itemRefl.Fill.BeginAnimation(LinearGradientBrush.EndPointProperty, endPointAnim);` – Ares Mar 03 '20 at 10:39