c# - : use correct height 中的动画控件

标签 c# wpf xaml animation storyboard

我有一个按钮和一个用户控件。 UserControl 的高度设置为 0。当我单击按钮时,我使用 StoryBoard 将 UserControl 的高度设置为 100。UserControl 变得可见。工作正常。

但现在我想摆脱 100 的固定值并设置为 UserControl 通常占据的大小的动画。有关如何执行此操作的任何建议?

这是我的 Storyboard。

<Storyboard x:Key="animateIn">
    <DoubleAnimation To="100" Storyboard.TargetName="myControl" Storyboard.TargetProperty="Height" Duration="0:0:0.1" />
</Storyboard>

最佳答案

改为动画 ScaleTransform.ScaleY

<UserControl x:Name="myControl">
    <UserControl.LayoutTransform>
        <ScaleTransform ScaleY="0" />
    </UserControl.LayoutTransform>
</UserControl>

<Storyboard x:Key="animateIn">
    <DoubleAnimation To="1"
        Storyboard.TargetName="myControl"
        Storyboard.TargetProperty="LayoutTransform.(ScaleTransform.ScaleY)"
        Duration="0:0:0.1" />
</Storyboard>

关于c# - : use correct height 中的动画控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6954654/

相关文章:

c# - 通过提供 Visual Studio 解决方案的发布文件夹来部署 wpf 应用程序

c# - 是否可以以编程方式密码保护 excel 电子表格?

c# - .NET MVC 3 在 C# 中向 SelectListItem 添加属性

c# - 在 C# wpf 应用程序中处理线程

c# - 将带有占位符 (`{0}` 的字符串添加到资源中是个好主意吗?

c# - WPF 矩形边框与两条破折号的连接线的角

c# - 遍历 NHibernate 实体的 IQueryable 时出现消息 "plan b"的 Antlr 异常

c# - 在 C# 中使用相同 UDP 端口的多个程序/实例

c# - Oxyplot 中的仿射变换

xaml - System.Type 作为转换器的属性 - 仅适用于代码隐藏中未使用的属性