我有一个滚动的文本行,我需要在文本结束后立即实现效果,将出现相同文本的开头。有什么想法吗?
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 :(得分: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 :(得分:1)
检查属性“RepeatCount”(如果内存为我服务),您可以将其设置为无穷大。