0
有沒有辦法讓TextBlock
的顏色變化動畫?Animate TextBlock color change
目前,我基本上使用進入/離開事件來改變顏色,我想要一個幾乎像淡出(但快速褪色,所以.1/.2秒),使其更好的視覺而不是瞬間的。
任何建議的最佳/最簡單的方法來做到這一點?
ps。由於約束,實際的代碼是vb.net,但我會接受c#.net的答案,因爲我可以閱讀都很好。只是學習WPF。
ta
有沒有辦法讓TextBlock
的顏色變化動畫?Animate TextBlock color change
目前,我基本上使用進入/離開事件來改變顏色,我想要一個幾乎像淡出(但快速褪色,所以.1/.2秒),使其更好的視覺而不是瞬間的。
任何建議的最佳/最簡單的方法來做到這一點?
ps。由於約束,實際的代碼是vb.net,但我會接受c#.net的答案,因爲我可以閱讀都很好。只是學習WPF。
ta
你想要一個ColorAnimation
。有該網頁既可以使用XAML的一個例子:
<!-- Animates the brush's color to orange
when the mouse leaves the rectangle. -->
<EventTrigger RoutedEvent="Rectangle.MouseLeave">
<BeginStoryboard>
<Storyboard>
<ColorAnimation
Storyboard.TargetName="MyAnimatedBrush"
Storyboard.TargetProperty="Color"
To="Orange" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
或代碼:
'
' Animate the brush's color to orange when
' the mouse leaves the rectangle.
'
Dim mouseLeaveColorAnimation As New ColorAnimation()
mouseLeaveColorAnimation.To = Colors.Orange
mouseLeaveColorAnimation.Duration = TimeSpan.FromSeconds(1)
Storyboard.SetTargetName(mouseLeaveColorAnimation, "MyAnimatedBrush")
Storyboard.SetTargetProperty(mouseLeaveColorAnimation, New PropertyPath(SolidColorBrush.ColorProperty))
Dim mouseLeaveStoryboard As New Storyboard()
mouseLeaveStoryboard.Children.Add(mouseLeaveColorAnimation)
AddHandler aRectangle.MouseLeave, Sub(sender As Object, e As MouseEventArgs) mouseLeaveStoryboard.Begin(Me)