WPF 以编程方式删除边距动画
如何删除动画故事板中堆栈面板两侧的边距,以便堆栈面板看起来已从后面的代码中移出?我需要在代码隐藏中执行此操作,因为我使用此动画的堆栈面板数量在运行时有所不同。谢谢:o)
How do I remove the margins of two sides of a stackpanel in an animation storyboard so it looks like the stackpanel has moved from the code behind? I need to do it in the code-behind because the number of stackpanels i use this animation on differs at runtime. Thanks :o)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定您是问如何在后面的代码中还是在动画 XAML 中设置边距值,所以我将在这两个方面都尝试一下。
在后面的代码中,您可以使用 DependencyProperty.SetValue 方法。例如: stackPanel.SetValue(MarginProperty, 0);
对于 XAML 动画,您可以添加厚度动画。例如:
I am not sure if you're asking how to set the margin value in the code behind or in the animation XAML, so I'll take a shot at both.
In the code behind you can use the DependencyProperty.SetValue method. For example:
stackPanel.SetValue(MarginProperty, 0);
For the XAML animation you can add a thickness animation. For example:
<ThicknessAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="stackPanel" Storyboard.TargetProperty="Margin">
<SplineThicknessKeyFrame KeyTime="00:00:00.025" Value="4,4,2,2"/>
</ThicknessAnimationUsingKeyFrames>