Blinking TextBlock

前端 未结 3 964
夕颜
夕颜 2020-12-06 03:56

Hi iam trying to make an Wpf TextBlock to blink. I want like when im clicking on an button then the textblock blinks. How can i achive this.

I have tried the followi

相关标签:
3条回答
  • 2020-12-06 04:29

    Make your trigger listen to the Loaded event rather than the MouseEnter event...

    <EventTrigger RoutedEvent="TextBlock.Loaded">
    
    0 讨论(0)
  • 2020-12-06 04:38

    There's no click event on a TextBlock. If you use a button with the textblock as content you can hook up your animation to the button's click event. You may need to style the button to remove 3D look or what else you may choose as default style for your buttons.

    0 讨论(0)
  • 2020-12-06 04:41

    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>
    

    0 讨论(0)
提交回复
热议问题