主要是用到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"
//从右往左滚动
时间: 2024-10-15 19:22:40