Click here to Skip to main content
15,877,939 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
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:
XML
<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.)
VB
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.
Posted

1 solution

thanks you I already make it work putting the button1_Click on a BackGroundWorker
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900