tags:

views:

48

answers:

1

I have a control template for a button that looks like this:

<ControlTemplate x:Key="CopyButton" TargetType="{x:Type Button}">
    <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text=">>>>"/>
</ControlTemplate>

How could I go about animating this so that when the mouse is hovering over the button the > arrows "move". I mean so that the text is something like "> ", ">> ", ">>> ", ">>>>", " >>>", " >>", " >" in a repeat.

+1  A: 

You can use a string animation. The result is however not the most professional looking in my opinion.

<Button 
        Name="myAnimatedButton" 
        Width="200"
        Content=">">
        <Button.Triggers>
            <EventTrigger RoutedEvent="Button.MouseEnter">
                <BeginStoryboard>
                    <Storyboard>
                        <StringAnimationUsingKeyFrames 
                            Storyboard.TargetName="myAnimatedButton" 
                            Storyboard.TargetProperty="(Button.Content)"
                            AutoReverse="True">
                            <DiscreteStringKeyFrame Value=">" KeyTime="0:0:0" />
                            <DiscreteStringKeyFrame Value=">>" KeyTime="0:0:1" />
                            <DiscreteStringKeyFrame Value=">>>" KeyTime="0:0:2" />
                            <DiscreteStringKeyFrame Value=">>>>" KeyTime="0:0:3" />
                            <DiscreteStringKeyFrame Value=" >>>" KeyTime="0:0:4" />
                            <DiscreteStringKeyFrame Value="  >>" KeyTime="0:0:5" />
                            <DiscreteStringKeyFrame Value="   >" KeyTime="0:0:6" />
                        </StringAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Button.Triggers>
    </Button>
Wallstreet Programmer
thanks this is what I was looking for.Point taken and now I will think harder about how this could better be implemented...if you have any suggestions...:)
David Ward
Create an arrow using Path and make it move by increasing its left margin using a double animation. For real fancy use an image of an arrow and a moving gif with a moving arrow and use the moving gif when mouse over.
Wallstreet Programmer
Agree except for the animated gif part. A WPF animation will look better than a animated gif at anything but 96 DPI, and it will look just as good at 96 DPI. A WPF animation is also easier to create and more flexible than an animated gif.
Ray Burns