WPF Remove Margin Animation Programmatically
How do I remove the margin开发者_Python百科s 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)
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>
精彩评论