My app has a custom user control (an ellipse with animation.) In my main window, I use both the usercontrol and a button
Image of the Control
I need to animate the control when the button is pressed:
private void button1_Click(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 10; i++)
{
userControl11.BlueAnimate();
dowork1();
userControl11.RedAnimate();
dowork2();
}
}
in my xml of the control i have the following definition:
<UserControl.Resources>
<Storyboard x:Name="Ellipse1Animation" x:Key="Ellipse1Animation">
<DoubleAnimation
x:Name="AnimacionEllipse"
Storyboard.TargetName="_Ellipse"
Storyboard.TargetProperty="Opacity"
From="0.0" To="1.0" Duration="0:0:1"
AutoReverse ="True"
RepeatBehavior="Forever"
/>
</Storyboard>
</UserControl.Resources>
The userControl11.BlueAnimate(); has the following code (It is almost the same for the other method; the only change is the color cast.)
Public Sub BlueAnimate()
Dim AnimJob As Action = Function()
Dispatcher.Invoke(DirectCast(
Function()
Dim sb As Storyboard = FindResource("Ellipse1Animation")
Dim Anim As DoubleAnimation = sb.Children(0)
_Ellipse.Fill = Brushes.Blue
Storyboard.SetTargetName(Anim, "_Ellipse")
sb.Beging()
End Function, Action))
End Function
Task.Factory.StartNew(AnimJob )
End Sub
When I cast the userControl11.BlueAnimate, it doesn't change. The visual interface stays frozen and doesn't work. Can someone help?
Thanks for your time.