Flashing TextBlock

Hi, I'm trying to make Wpf TextBlock blink. I want that when I click on the button, then the text block is blinking. How can i achieve this.

I have tried the following.

<TextBlock Name="txtBlockScannerText" Margin="10,0,0,0" Style="{StaticResource TextBlockNormal}" Text="Skanna Inleverans listan"> <TextBlock.Triggers> <EventTrigger RoutedEvent="TextBlock.MouseEnter"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard BeginTime="00:00:00" RepeatBehavior="Forever" Storyboard.TargetName="txtBlockScannerText" Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)"> <ColorAnimation From="Black" To="Red" Duration="0:0:1"/> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </TextBlock.Triggers> </TextBlock> 

But with this code, it only blinks when my mouse enters it. How can I cause a blinking in a button click event. Or what can I call an event blinking. thanks for the help

+1
source share
3 answers

There is no click event in TextBlock. If you use a button with a text block as content, you can connect the animation to the button press event. You may need to style the button to remove the 3D view or what else you can choose as the default style for your buttons.

+5
source

Here is the solution

 <TextBlock Name="txtBlockScannerText" Margin="10,0,0,0" Text="WELCOME"> </TextBlock> <Button Content="Click Me" Height="23" HorizontalAlignment="Left" Margin="225,43,0,0" Name="button1" VerticalAlignment="Top" Width="75"> <Button.Triggers> <EventTrigger RoutedEvent="Button.Click"> <EventTrigger.Actions> <BeginStoryboard> <Storyboard BeginTime="00:00:00" RepeatBehavior="Forever" Storyboard.TargetName="txtBlockScannerText" Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)"> <ColorAnimation From="Black" To="Blue" Duration="0:0:1"/> </Storyboard> </BeginStoryboard> </EventTrigger.Actions> </EventTrigger> </Button.Triggers> </Button> 

+5
source

Make the trigger listen for the Loaded event, not the MouseEnter event ...

 <EventTrigger RoutedEvent="TextBlock.Loaded"> 
+3
source

All Articles