0
\$\begingroup\$

I have a Style for a Button which:

  1. Animates the Opacity when the IsMouseOver property is False.

  2. When IsMouseOver = True the Opacity to be restored to 100% and the animation to stop.

The Style works, but I am left wondering if there is a better way to achieve (2)?

At the moment I am using a Storyboard and DoubleAnimation which all seems 'excessive' to just make the Opacity 100%?

Here is the XAML:

<Style TargetType="Button">
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="False">
            <Trigger.EnterActions>
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation 
                            Storyboard.TargetProperty="Opacity"
                            From="1.0"
                            To="0.1"
                            Duration="0:0:0.5"
                            AutoReverse="True"
                            RepeatBehavior="Forever" />
                    </Storyboard>
                </BeginStoryboard>
            </Trigger.EnterActions>
        <Trigger.ExitActions>
            <BeginStoryboard>
                <Storyboard>
                   <DoubleAnimation Storyboard.TargetProperty="Opacity"
                                    From="1.0"
                                    To="1.0"
                                    Duration="0:0:0"
                                    />
               </Storyboard>
          </BeginStoryboard>
      </Trigger.ExitActions>

  </Trigger>

</Style.Triggers>
</Style>
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.