WPF动画自定义控件中的问题 [英] Problem in WPF Animation Custom Control
问题描述
我的应用程序有一个自定义用户控件(带动画的椭圆。)在我的主窗口中,我同时使用usercontrol和一个按钮
控制图像
我需要在按下按钮时为控件设置动画:
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();
}
}
我的xml控件中的
我有以下定义:
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>
userControl11.BlueAnimate();具有以下代码(对于其他方法几乎相同;唯一的变化是偏色。)
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
当我投射userControl11.BlueAnimate时,它不会改变。可视界面保持冻结状态,不起作用。有人可以帮忙吗?
感谢您的时间。
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.
推荐答案
谢谢你我已经让它工作了button1_点击BackGroundWorker
thanks you I already make it work putting the button1_Click on a BackGroundWorker
这篇关于WPF动画自定义控件中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!