.net – 彩色动画不起作用

我有一个名为“b”的按钮,我要将背景从黑色变为白色,但它不起作用.

错误

‘System.Windows.Media.Animation.ColorAnimation’ animation object cannot be used to animate property ‘Background’ because it is of incompatible type ‘System.Windows.Media.Brush’.

我的代码

Dim changeColor As New Animation.ColorAnimation

changeColor.From = Colors.Black
changeColor.To = Colors.White
changeColor.Duration = TimeSpan.FromSeconds(0.2)

Animation.Storyboard.SetTarget(changeColor,b)
Animation.Storyboard.SetTargetProperty(changeColor,New PropertyPath(BackgroundProperty))

Dim sb As New Animation.Storyboard
sb.Children.Add(changeColor)
sb.Begin()

有什么想法吗?

解决方法

背景是Brush类型,无法使用ColorAnimaion进行动画处理.但是,SolidColorBrush具有Color属性,因此您可以执行以下操作:

Storyboard.SetTargetProperty(changeColor,new PropertyPath("Background.Color"));

相关文章

如何在Silverlight4(XAML)中绑定IsEnabled属性?我试过简单的...
我正在编写我的第一个vb.net应用程序(但我也会在这里标记c#,...
ProcessFile()是在UIThread上运行还是在单独的线程上运行.如...
我从同行那里听说,对sharepoint的了解对职业生涯有益.我们不...
我正在尝试保存一个类我的类对象的集合.我收到一个错误说明:...
我需要根据Silverlight中的某些配置值设置给定控件的Style.我...