繁体   English   中英

如何在xaml中将父容器的height属性分配给DoubleAnimation的to参数?

[英]How to assign the height property of the parent container to the to parameter of DoubleAnimation in xaml?

如标题所述,我想知道如何将容器的高度(或ActualHeight )分配给xaml中DoubleAnimationTo参数/属性?

这是我的代码:

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

您可以像这样将Binding应用于双重动画的To属性:

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

我认为这可以解决您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM