工作时动画

时间:2013-07-15 14:53:07

标签: c# wpf vb.net animation controls

我的应用程序有一个自定义用户控件(带动画的椭圆。)在我的主窗口中,我同时使用了usercontrol和一个按钮

Sample diagram

我需要在按下按钮时为控件设置动画:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        for (int i = 0; i < 10; i++)
        {
            userControl11.BlueAnimate();
            dowork1();
            userControl11.RedAnimate();
            dowork2();
        }
    }

在我的控件的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>

userControl11.BlueAnimate();具有以下代码(对于其他方法几乎相同;唯一的变化是偏色。)

   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.Begin()
               End Function, Action))
               End Function
        Task.Factory.StartNew(AnimJob )
    End Sub

当我投射userControl11.BlueAnimate时,它不会改变。可视界面保持冻结状态,不起作用。有人可以帮忙吗?

感谢您的时间。

0 个答案:

没有答案