我想知道是否有人可以帮助我 - 我有一个标签,当在后面的代码中调用方法时,我需要能够在任何两种颜色之间交叉淡入淡出。
到目前为止我最好的尝试:
Private OldColor as Color = Colors.White
Sub SetPulseColor(ByVal NewColor As Color)
Dim F As New Animation.ColorAnimation(OldColor, NewColor, New Duration(TimeSpan.Parse("00:00:01")))
OldColor = NewColor
F.AutoReverse = False
PulseLogo.BeginAnimation(Label.ForegroundProperty, F)
End Sub
我遇到的问题是 ColorAnimation 返回一个 Media.Color 并且 Foreground 的属性类型是 Brush。
我知道如何创建合适的画笔,但不知道如何在动画中创建。
从谷歌搜索,我似乎需要一个转换器:
<ValueConversion(GetType(SolidColorBrush), GetType(SolidColorBrush))> _
Public Class ColorConverter
Implements IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
Dim Color As Color = DirectCast(value, Color)
Return New SolidColorBrush(Color)
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
Return Nothing
End Function
End Class
但是我看到的所有示例都将它绑定到 XAML 中的动画 - 我想在后面的代码中执行它......
有人可以指出我正确的方向吗?
谢谢