Search code examples
c#wpfxamlstoryboarddoubleanimation

Move a label in XAML


all I'm trying to do is move a label from one position to another, but when I use the following code and run the application, the IDE tells me that the application went into break mode and then stopped.

The following code is all I have inside the Grid, there is nothing else there and the .cs file is clean (only the constructor with the initializeComponents).

I am using Blend from Visual Studio 2017 Enterprise Edition

<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>

Please help me, I don't know what is wrong


Solution

  • NaN error is coming above code. To remove NaN error add "From" and "To" in Double animation in above code. From="100" To="500" Duration="0:0:10"

    Also change Foreground="Black" in labelTitle, So the label will be visible.