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.
source share