2010-06-15 91 views
2

我有一个按钮,看起来像这样的控件模板:WPF按钮动画

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

我怎么能去动画这一点,以便当鼠标悬停在按钮>箭头“移动”。我的意思是这样的文字就像"> ", ">> ", ">>> ", ">>>>", " >>>", " >>", " >"重复。

回答

3

您可以使用字符串动画。然而,结果并不是我认为的最专业的。

<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> 
+0

感谢这就是我一直在寻找。 需要采取的一点,现在我会更加努力地思考如何更好地实施...如果您有任何建议... :) – 2010-06-15 13:53:29

+0

使用路径创建一个箭头,并使用双动画增加其左边距使其移动。对于真正的幻想使用箭头的图像和移动的箭头的移动gif,并使用鼠标移动时移动的gif。 – 2010-06-15 15:20:35

+0

除了动画gif部分以外,还有其他同意。除了96 DPI以外,WPF动画看起来会比动画GIF更好,96 DPI看起来也不错。 WPF动画也比动画GIF更容易创建并且更加灵活。 – 2010-06-16 02:12:34