在我的应用程序中,我有像扩展器一样的组框。当我需要折叠一个组框时,我将其高度设置为 0。当我需要展开它时,我将其高度设置为自动 (double.Nan) 是否可以使用 Storyboard 来执行此操作。我怎么能提前知道自动高度。 Expression blend 不能让我为汽车制作动画。
最佳答案
因为我讨厌比例变换,因为我觉得它很丑,所以我寻找了另一种解决方案。
好吧,我知道这是一篇旧帖子,存在许多解决方法,但我的很简单,即使有人肯定找到了,我也没有在其他地方阅读它。
不是将高度从 X 设置为 Auto
的动画(这是不可能的),您可以让高度设置为 Auto
并设置 MaxHeight
属性的动画:
<MyControl x:Name="ctrlAutoHeight" Height="Auto">
<MyControl.Triggers>
<EventTrigger RoutedEvent="myRoutedEvent">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ctrlAutoHeight"
Storyboard.TargetProperty="MaxHeight"
From="0.0"
To="{Binding ElementName=ParentControl, Path=ActualHeight}"
Duration="0:0:1"
AutoReverse="False"
/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</MyControl.Triggers>
</MyControl>
关于c# - 组框的动画高度从 0 到自动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6554437/