.net - 彩色动画不起作用

标签 .net wpf vb.net silverlight animation

我有一个名为“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/

相关文章:

c# - 使用 JSON 字符串将多个值添加到 1 个用户声明中

c# - .NET BindingSource 过滤器语法引用

mysql - 如何填充 datagridview VB.Net

vb.net - 从 VB.net 中的字符串中去除所有标点符号

c# - "Using"语句如何从 C# 转换为 VB?

c# - 启动 Windows 服务是否总是在启动应用程序之前运行?

.net - .NET 图像类的内存使用和碎片 : Bitmap vs. 元文件

c# - WPF 错误的 KeyDown ASCII 代码

wpf - WPF ListView /数据网格内的按钮

c# - SetCurrentValue myLabel.BackgroundProperty 不破坏绑定(bind)