我的页面有一部分专门用于显示制作人员名单,并且有三个垂直滚动的文本 block 。然而,我需要每行在就位(面板中的位置)时暂停,然后在一秒钟左右后继续。如果不让这一切变得非常复杂,我不知道该怎么做。我让所有三行一起滚动,但不知道如何使其暂停。
我什至尝试过 DoubleAnimationUsingKeyFrames 但也无法正常工作。
有什么指点吗?
最佳答案
诀窍是设置动画的BeginTime
,如本示例所示。
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Titles" SizeToContent="WidthAndHeight">
<Window.Resources>
<Style TargetType="Grid">
<Setter Property="Width" Value="300" />
<Setter Property="Height" Value="100" />
</Style>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="FontSize" Value="20" />
</Style>
<Style TargetType="StackPanel">
<Setter Property="Canvas.Top" Value="200" />
<Style.Triggers>
<EventTrigger RoutedEvent="Loaded">
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Top)" From="300" To="100" BeginTime="0:00:00" Duration="0:00:02" />
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Top)" From="100" To="0" BeginTime="0:00:04" Duration="0:00:01" />
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Top)" From="0" To="-100" BeginTime="0:00:06" Duration="0:00:01" />
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Top)" From="-100" To="-300" BeginTime="0:00:08" Duration="0:00:02" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Canvas Width="300" Height="300">
<StackPanel>
<Grid>
<TextBlock Text="Name 1" />
</Grid>
<Grid>
<TextBlock Text="Name 2" />
</Grid>
<Grid>
<TextBlock Text="Name 3" />
</Grid>
</StackPanel>
</Canvas>
</Window>
关于.net - WPF - 如何使文本垂直滚动并暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4058922/