Sam Sam - 6 months ago 129
C# Question

UWP blinking text

this might sounds very simple, but I couldn't find a way to do it.

I just want a blinking text in TextBlock. Is there a way to do it easily?

The only way I can think of is to use timer and change the TextBlock foreground manually. Surely there is an easy way to do it. I am just not able to figure it out.



You could declare a Storyboard animation in your XAML markup which blinks the text forever:

<TextBlock Text="I'm Blinking!">
        <Style TargetType="TextBlock">
                <Storyboard x:Key="flashAnimation" >
                    <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0" AutoReverse="True" Duration="0:0:0.5" RepeatBehavior="Forever" />

This is using my experience from WPF and WinRT XAML, but I'm pretty sure that UWP uses the same Storyboard animations.

Here's Microsoft's handy reference on MSDN: Animations Overview.

Hope this helps!