.net - WPF - 如何使文本垂直滚动并暂停

标签 .net wpf

我的页面有一部分专门用于显示制作人员名单,并且有三个垂直滚动的文本 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/

相关文章:

.net - 我对 async/await、它的工作原理及其优点的理解是否正确?

c# - 关闭 View 会将 ViewModel 的属性设置为 null

c# - WPF将 slider 的鼠标位置值绑定(bind)到文本 block

c# - protobuf-net 使用 DynamicType 序列化 System.Object 抛出异常

c# - 检测 MSMQ 错误

WPF Scale Transform 和 ScrollViewer - 缩放时无法滚动超出原始大小

c# - 在 WPF DataGrid 中使用 Enter 键作为 Tab

c# - Windows 8 中的 .NET : AppContract, Marketplace 和 WPF/C# 从开发的角度来看

c# - 如何再次请求中止的 HttpWebRequest?

.net - Xpath可在Notepad++中工作,但不能在.NET应用程序中工作