c# - 在 XAML 中移动标签

标签 c# wpf xaml storyboard doubleanimation

我想做的只是将标签从一个位置移动到另一个位置,但是当我使用以下代码并运行应用程序时,IDE 告诉我应用程序进入中断模式然后停止。

下面的代码是我在 Grid 中的所有代码,那里没有其他任何东西,.cs 文件是干净的(只有带有 initializeComponents 的构造函数)。

我正在使用 Visual Studio 2017 企业版的 Blend

<Label x:Name="labelTitle" Foreground="White" FontSize="36" FontWeight="Bold"  HorizontalAlignment="Center" VerticalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center">
        <Label.Triggers>
            <EventTrigger RoutedEvent="Label.Loaded">
                <BeginStoryboard>
                    <Storyboard>
                        <DoubleAnimation
                            Storyboard.TargetName="labelTitle"
                            Storyboard.TargetProperty="(Canvas.Top)"
                            To="500" Duration="0:0:10" />                           
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Label.Triggers>
        Welcome
    </Label>

请帮帮我,我不知道哪里出了问题

最佳答案

代码上方出现 NaN 错误。要删除 NaN 错误,请在上面代码的双动画中添加“From”和“To”。 从 ="100"到 ="500"持续时间 ="0:0:10"

同时在 labelTitle 中更改 Foreground="Black",因此标签将可见。

关于c# - 在 XAML 中移动标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46395627/

相关文章:

c# - 为什么 C# 自动实现的属性是公共(public)的?

c# - 如何在 WPF 中将组合框绑定(bind)到其他项目的枚举?

c# - 添加到 "open recent files"

wpf - (WPF) 将 OneWayToSource 与转换器绑定(bind)会导致立即异常

c# - WPF 与 Datacontext 绑定(bind)

XAML 样式仅应用于第一个矩形。如何使其适用于所有人?

c# - Typescript Angular 2 Http post 到 C# MVC

c# - .Net : Running an embedded interpreter 的 Python

c# - 如何解决 : why I can't obtain a lock?

c# - 如何以及在何处为简单 XAML 窗口中的转换器创建 StaticResource 键?