Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

To set blinking effect on button in XAML

Tags:

.net

wpf

xaml

my requirement is I want to set blink effect on button2 when button1 is clicked. I did refer this example for blinking effect on textblock.

Blinking TextBlock?

but its not working for my button2. I can show you xaml code if you want. plz help me out. Thanks.

like image 881
deathrace Avatar asked Dec 27 '22 06:12

deathrace


1 Answers

Try this:

  <Button Name="button1" Margin="10" Content="Animate Button2!">
    <Button.Triggers>
      <EventTrigger RoutedEvent="Button.Click">
        <EventTrigger.Actions>
          <BeginStoryboard>
            <Storyboard BeginTime="00:00:00" 
                                    RepeatBehavior="Forever" 
                                    Storyboard.TargetName="button2" 
                                    Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)">
              <ColorAnimation From="Black" To="Red" Duration="0:0:1"/>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger.Actions>
      </EventTrigger>
    </Button.Triggers>
  </Button>

  <Button Name="button2" Margin="10" Content="I will get animated!"></Button>

In case you want to animate the Background: This is not that easy to achieve as the framework is using the background for internal stuff, e.g. the hover animation.

See Blinking button on WPF application

like image 53
SvenG Avatar answered Jan 09 '23 08:01

SvenG