1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
public static class SmartTextAnimation
{
/// <summary>
/// Add a fading animation to a 'TextBlock'-Control
/// </summary>
///
/// <param name="FadingTextList">The generic List of all strings that have to be shown</param>
/// <param name="TextPromptDuration">The duration of the text prompt in milliseconds</param>
/// <param name="FadingSpeed">The speed of the text fading animation in milliseconds</param>
///
/// <returns></returns>
///
public static void AddSmartFadingAnimation( this TextBlock TextBoxToAnimate, List<string> FadingTextList,
double TextPromptDuration, double FadingSpeed )
{
int index = 0;
DoubleAnimation FadeOutAnimation = new DoubleAnimation()
{
Duration = new Duration( TimeSpan.FromMilliseconds( FadingSpeed ) ),
To = 0, BeginTime = TimeSpan.FromMilliseconds( TextPromptDuration )
};
DoubleAnimation FadeInAnimation = new DoubleAnimation()
{
Duration = new Duration( TimeSpan.FromMilliseconds( FadingSpeed ) ),
To = 1, BeginTime = TimeSpan.FromMilliseconds( TextPromptDuration + FadingSpeed )
};
Storyboard FadeInAndOutStoryboard = new Storyboard() { RepeatBehavior = RepeatBehavior.Forever };
Storyboard.SetTargetProperty( FadeOutAnimation, new PropertyPath( "(Opacity)" ) );
Storyboard.SetTargetProperty( FadeInAnimation, new PropertyPath( "(Opacity)" ) );
Storyboard.SetTarget( FadeOutAnimation, TextBoxToAnimate );
Storyboard.SetTarget( FadeInAnimation, TextBoxToAnimate );
FadeInAndOutStoryboard.Children.Add( FadeOutAnimation );
FadeInAndOutStoryboard.Children.Add( FadeInAnimation );
TextBoxToAnimate.Text = FadingTextList[index++];
FadeOutAnimation.CurrentStateInvalidated += new EventHandler( (sender, eArgs) =>
{
if ( (sender as Clock).CurrentState == ClockState.Filling )
{
TextBoxToAnimate.Text = FadingTextList[index];
if (++index == FadingTextList.Count) index = 0;
}
} );
FadeInAndOutStoryboard.Begin();
}
}
|