2011-02-24 23 views
1

我有一個滾動文本行,並且我需要在文本結束後立即達到效果,同一文本的開始會出現。有任何想法嗎?如何製作一個環形的TranslateTransform?

UPD文本是靜態的(不改變) 目前動畫代碼是這樣的:

    <EventTrigger RoutedEvent="FrameworkElement.Loaded"> 
        <BeginStoryboard> 
         <Storyboard RepeatBehavior="Forever"> 
          <DoubleAnimation From="200" To="-200" Storyboard.TargetName="translate" 
           Storyboard.TargetProperty="Y" Duration="0:0:5" /> 
         </Storyboard> 
        </BeginStoryboard> 

它工作正常,但是當到達最終它抽搐(和跳回到起點)。我需要避免這一點。

+0

是文本的靜態(固定長度)?你目前使用什麼代碼來動畫文本? – foson 2011-02-24 21:16:22

回答

2

如果文本長度是靜態的,最簡單的方法是創建屏幕外的文本的多個副本,並將副本/副本設置爲與原始文件相同的位置。如果你有一個動畫循環這樣一來,就不會有「混蛋」

<UserControl 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
x:Class="SilverlightApplication3.MainPage" 
Width="200" Height="480"> 
<UserControl.Resources> 
    <Storyboard x:Name="TextScrollStoryboard"> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="offscreenTextBlock" RepeatBehavior="Forever"> 
      <EasingDoubleKeyFrame KeyTime="0" Value="-200"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2" Value="0"/> 
     </DoubleAnimationUsingKeyFrames> 
     <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.TranslateX)" Storyboard.TargetName="textBlock" RepeatBehavior="Forever"> 
      <EasingDoubleKeyFrame KeyTime="0" Value="0"/> 
      <EasingDoubleKeyFrame KeyTime="0:0:2" Value="200"/> 
     </DoubleAnimationUsingKeyFrames> 
    </Storyboard> 
</UserControl.Resources> 

<i:Interaction.Triggers> 
    <i:EventTrigger> 
     <ei:ControlStoryboardAction Storyboard="{StaticResource TextScrollStoryboard}"/> 
    </i:EventTrigger> 
</i:Interaction.Triggers> 

<Grid x:Name="LayoutRoot" Background="#FFBBBBBB"> 
    <TextBlock x:Name="textBlock" Text="This is some text" RenderTransformOrigin="0.5,0.5" > 
     <TextBlock.RenderTransform> 
      <CompositeTransform TranslateX="0"/> 
     </TextBlock.RenderTransform> 
    </TextBlock> 
    <TextBlock x:Name="offscreenTextBlock" Text="This is some text" RenderTransformOrigin="0.5,0.5" > 
     <TextBlock.RenderTransform> 
      <CompositeTransform TranslateX="-200"/> 
     </TextBlock.RenderTransform> 
    </TextBlock> 
</Grid> 

1

檢查屬性「RepeatCount」(如果內存適合我),可以將其設置爲無窮大。

+0

它不會真的圈。它只會從最後跳到開頭,製作一個「混蛋」 – user626528 2011-02-25 09:58:44

+0

是的,但這是製作我聽說過的循環動畫的唯一方法 - 不使用代碼背後 – Maciek 2011-02-25 13:42:32