2011-11-28 2 views
0

내 응용 프로그램에 TextBlock이 있습니다. TranslateTransform Animation 각 단어를 내 TextBlock에서 번역하려고합니다. 이것은 Text Effect의 Exist In PowerPoint와 유사합니다. 예를 들어TextBox TranslateTransform 애니메이션

: 각 단어는 최대 20 픽셀 이동 한 후 내 연구에서 마지막 위치

+0

이 질문과 대답은 "왜 TextBox.Text가 WPF 애니메이션 가능하지 않습니까?"라고 대답합니다. http://stackoverflow.com/questions/2603683/why-isnt-textbox-text-in-wpf-animatable – punker76

+0

모든 단어에 대해 별도의 'TextBlock'을 사용하는 것이 더 쉽다고 생각합니다. – icebat

답변

0

에 반환, 나는 내가이 일을 할 수있는 방법을 참조하는 데 사용 Microsoft에서 샘플을 발견.

먼저 우리가 TextBlock이 들어 TextEffects을 정의

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

둘째, 우리는 애니메이션을 정의

단어의 Int32AnimationUsingKeyFrames으로 증가 PositionCount를 들어 애니메이션과 정의의 Int32AnimationUsingKeyFrames.KeyFrames 수는 텍스트에 존재) 1

2) TranslateTransform의 애니메이션 각 단어 이동

예 : 3 단어의 경우 :

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