0

As the title says, I want to know how to assign the height(or ActualHeight) of the container to the To parameter/attribute of DoubleAnimation in xaml?

Here is my code:

<Canvas Name="animCanvas">
    <Rectangle 
        Name="animSquare"
        Canvas.Left="0"
        Fill="AliceBlue"
        Stroke="Bisque"
        StrokeThickness="5"
        Width="100"
        Height="100"
        >
        <Rectangle.Triggers>
            <EventTrigger RoutedEvent="Window.Loaded">
                <BeginStoryboard>
                    <Storyboard RepeatBehavior="Forever">
                        <DoubleAnimation
                            Storyboard.TargetName="animSquare"
                            Storyboard.TargetProperty="(Canvas.Top)"
                            From="0"
                            To="500" <!-- I want to set it to the containers height -->
                            Duration="0:0:1"
                        />
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </Rectangle.Triggers>
    </Rectangle>
</Canvas>
smalinux
  • 1,132
  • 2
  • 13
  • 28
someone
  • 425
  • 8
  • 16
  • Perhaps use code-behind to create the storyboard? To get you started: [Creating Storyboard in code behind in WPF](http://stackoverflow.com/questions/15900627/creating-storyboard-in-code-behind-in-wpf). In code behind, you can definitely find out the parent's height and pass it to the `To` parameter. – Keyur PATEL Sep 15 '16 at 02:17
  • I prefer to use plain xaml as long as possible. Isn't it possible using plain xaml? – someone Sep 15 '16 at 02:35
  • Actually the answer below has got it. – Keyur PATEL Sep 15 '16 at 04:06

1 Answers1

0

You can apply Binding to the To property of double animation like this :

To="{Binding ElementName=animSquare, Path=Height}"

I think this would solve your issue.

ViVi
  • 4,339
  • 8
  • 29
  • 52