简体   繁体   English

如何在WPF中移动StackPanel

[英]How to move a StackPanel in WPF

I would like to move a StackPanel horizontally when the user clicks a button. 我想在用户单击按钮时水平移动StackPanel I'm implementing DoubleAnimation with TargetName and TargetProperty . 我正在使用TargetNameTargetProperty实现DoubleAnimation But, I don't know which TargetProperty to use. 但是,我不知道使用哪个TargetProperty

Can anyone help me? 谁能帮我?

If you put the StackPanel inside a Canvas you can achieve this behavior by setting the Canvas.X and Canvas.Y properties. 如果将StackPanel放在Canvas ,则可以通过设置Canvas.XCanvas.Y属性来实现此行为。 Alternatively you could animate the Margin of the StackPanel by using ThicknessAnimation . 或者,您可以使用ThicknessAnimationStackPanelMargin设置动画。 Check out this post for a similar request. 查看此帖子以获取类似请求。

Another method would be a TranslateTransform applied to the RenderTransform of the StackPanel. 另一种方法是应用于StackPanel的RenderTransformTranslateTransform The TargetProperty path for the animation then would be RenderTransform.X . 然后动画的TargetProperty路径将是RenderTransform.X

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

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