Silverlight实现滚动文字

主要是用到DoubleAnimation 标签:

<Canvas x:Name="c1" Margin="2,25,2,2">
            <Canvas.Triggers>
                <EventTrigger RoutedEvent="Canvas.Loaded" >
                    <BeginStoryboard>
                        <Storyboard x:Name="animation" RepeatBehavior="Forever" >
                            <DoubleAnimation Storyboard.TargetName="ScrollingUp"                    
                                             Storyboard.TargetProperty="(Canvas.Left)" From="1024" To="0" Duration="0:0:15"  />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Canvas.Triggers>
            <TextBlock x:Name="ScrollingUp" FontWeight="Bold" Foreground="Red"  FontSize="12" TextWrapping="Wrap" Height="113">
                滚动文字
            </TextBlock>
        </Canvas>
 

这里是滚动文字的代码,主要的就是StoryBoard里的属性设置:

Storyboard.TargetProperty="(Canvas.Top)" From="100" To="0" Duration="0:0:10"

同理,其他方向如下设置即可:

Storyboard.TargetProperty="(Canvas.Top)" From="0" To="100" Duration="0:0:10"   //从上往下滚动

Storyboard.TargetProperty="(Canvas.Left)" From="0" To="100" Duration="0:0:10"   //从左往右滚动

Storyboard.TargetProperty="(Canvas.Left)" From="100" To="0" Duration="0:0:10"   //从右往左滚动

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。