我有一个名为“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()
有什么想法吗?
最佳答案
值得注意的是,可以使用以下形式的表达式在 XAML 中解决相同的问题:
<ColorAnimation Duration="0:0:0.2" From="Black" To="White"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
Storyboard.TargetName="Body" />
关于.net - 彩色动画不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5941405/