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

拈花ヽ惹草 提交于 2019-12-07 01:34:57

问题


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:


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();


来源:https://stackoverflow.com/questions/13532501/fade-in-out-a-textblock-in-a-windows-store-application-xaml-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!