Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fade in/out a TextBlock in a Windows Store Application [XAML/C#]

can someone explain me how can I add a fade in and a fade out animation to a textblock when I load a form in a Windows Store application? I tried the WPF method but it didn't work... Thank you :)

like image 765
DarioDP Avatar asked Nov 23 '12 16:11

DarioDP


1 Answers

Not sure if this is what you're looking for (or what "WPF method" didn't work), but with this resource:

<Page.Resources>
    <Storyboard x:Name="Storyboard1">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="textBlock">
            <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            <EasingDoubleKeyFrame KeyTime="0:0:4" Value="1"/>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>
</Page.Resources>

invoked from OnNavigatedTo you'll get a fade-in effect (here on a specific instance called textBlock.) Obviously, you can adjust the duration and easing function to your liking - and perhaps generalize for use across various controls.

var f = this.Resources["Storyboard1"] as Storyboard;
if (f != null) f.Begin();
like image 176
Jim O'Neil Avatar answered Nov 06 '22 13:11

Jim O'Neil