Windows 8 Metro TextBlock Animation

In my metro application, I have a text block that I would have to animate to 100% opacity, and then back to 0% opacity if the if statement is true. How can i do this?

I turned around a lot, but all the animation tutorials confuse me.

+4
source share
1 answer

You can do something similar in C # to animate from 0 to 1:

var sb = new Storyboard(); opacityAnimation = new DoubleAnimation { From = 0.0, To = 1.0, Duration = TimeSpan.FromSeconds(1.5) }; Storyboard.SetTarget(opacityAnimation, textBlock); Storyboard.SetTargetProperty(opacityAnimation, "Opacity"); sb.Children.Add(opacityAnimation); sb.Begin(); 

You can also define it in XAML:

 <Storyboard x:Name="fadeInStoryboard" Storyboard.TargetName="myTextBlock" Storyboard.TargetProperty="Opacity"> <DoubleAnimation From="0" To="1.0" Duration="0:0:1.5" /> </Storyboard> 

- then run it in the code behind:

 fadeInStoryboard.Begin(); 

Depending on your scenario, using visual states and defining a storyboard as a visual state transition may be ideal.

+5
source

Source: https://habr.com/ru/post/1415761/


All Articles