none
How to animate the Canvas.Top property

    Question

  • Hi,

    I am trying to animate movement of the TextBlock object and my attempt to change the Canvas.Top property didn't work.

        <Canvas
            x:Name="myCanvas"
            Width="100"
            Height="20"
            Canvas.Top="200"
            Canvas.Left="100"
        >
            <TextBlock
                x:Name="anitext"
                Text="animated text">
                <TextBlock.Triggers>
                    <EventTrigger RoutedEvent="TextBlock.Loaded">
                        <BeginStoryboard>
                            <Storyboard
                                x:Name="storyFade"
                                Storyboard.TargetName="anitext"
                            >
                                <DoubleAnimation
                                    BeginTime="0:0:0"
                                    Storyboard.TargetProperty="Canvas.Top"
                                    From="200" To="100" Duration="0:0:0.2" AutoReverse="True"
                                />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </TextBlock.Triggers>
            </TextBlock>
        </Canvas>

    I didn't get an error either. How should I do this?
    Friday, January 19, 2007 3:06 PM

Answers

  • The TargetProperty needs to be in parenthesis like:

     

    <Canvas
            x:Name="myCanvas"
            Width="100"
            Height="20"
            Canvas.Top="200"
            Canvas.Left="100"
        >
     <TextBlock x:Name="anitext" Text="animated text">
                <TextBlock.Triggers>
                    <EventTrigger RoutedEvent="TextBlock.Loaded">
                        <BeginStoryboard>
                            <Storyboard
        Storyboard.TargetName="anitext">
                                <DoubleAnimation
                                    BeginTime="0:0:0"
                                    Storyboard.TargetProperty="(Canvas.Top)"
                                    From="0" To="100" Duration="0:0:0.2" AutoReverse="True"
                                />
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger>
                </TextBlock.Triggers>
            </TextBlock>
        </Canvas>

    --

    Bryant

    Friday, January 19, 2007 9:20 PM