2011-11-28 56 views
0

我在我的应用程序中有一个TextBlock。我想TranslateTransform动画中的每个单词在我的 TextBlock中。这将与PowerPoint中的文字效果存在类似。TextBox TranslateTransform Animation

例如:每个字将移动20像素最多,然后返回到最后的位置

+0

听起来像这个问题和答案“为什么WPF中的TextBox.Text不是动画?” http://stackoverflow.com/questions/2603683/why-isnt-textbox-text-in-wpf-animatable – punker76

+0

我觉得为每个单词使用单独的“TextBlock”可能更容易。 – icebat

回答

0

在我的研究,我发现了一个样本来自微软,我常看我怎样才能使这项工作。

首先我们定义TextEffects对于TextBlock的:

<TextBlock.TextEffects> 
            <TextEffectCollection> 
             <TextEffect PositionCount="1" x:Name="TxtEffect"> 
              <TextEffect.Transform> 
               <TranslateTransform x:Name="Transform" X="0" Y="0"></TranslateTransform> 
              </TextEffect.Transform> 
             </TextEffect> 
            </TextEffectCollection> 
</TextBlock.TextEffects> 

其次,我们定义动画:

1)动画增加PositionCount随着Int32AnimationUsingKeyFrames并定义的 Int32AnimationUsingKeyFrames.KeyFrames字的数量以文本

2)TranslateTransform动画移动每个字

三个词的示例:

<BeginStoryboard> 
            <Storyboard RepeatBehavior="Forever"> 
             <DoubleAnimation Storyboard.TargetName="Transform" Storyboard.TargetProperty="Y" From="0" To="20" BeginTime="0:0:0" Duration="0:0:0.25"/> 
             <DoubleAnimation Storyboard.TargetName="Transform" Storyboard.TargetProperty="Y" From="20" To="-20" BeginTime="0:0:0.25" Duration="0:0:0.5" /> 
             <DoubleAnimation Storyboard.TargetName="Transform" Storyboard.TargetProperty="Y" From="-20" To="0" BeginTime="0:0:0.75" Duration="0:0:0.25" /> 
            </Storyboard> 
</BeginStoryboard> 

<BeginStoryboard Name="TxtEf"> 
       <Storyboard> 
         <Int32AnimationUsingKeyFrames Storyboard.TargetName="TxtEffect" 
                     Storyboard.TargetProperty="PositionStart" 
                     Duration="0:0:2.5" AutoReverse="True" RepeatBehavior="Forever"> 
              <Int32AnimationUsingKeyFrames.KeyFrames> 

               <DiscreteInt32KeyFrame Value="0" KeyTime="0:0:0" /> 
               <DiscreteInt32KeyFrame Value="1" KeyTime="0:0:1" /> 
               <DiscreteInt32KeyFrame Value="2" KeyTime="0:0:2" /> 

              </Int32AnimationUsingKeyFrames.KeyFrames> 

          </Int32AnimationUsingKeyFrames> 
       </Storyboard>