Fade in/out a TextBlock in a Windows Store Applica

2019-04-24 18:17发布

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 :)

1条回答
三岁会撩人
2楼-- · 2019-04-24 18:43

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();
查看更多
登录 后发表回答