可以对RowDefinition进行动画处理吗? [英] Is it possible to animate a RowDefinition?
问题描述
我有两行网格.在第一行中,我有一个画布,在第二行中,我有一个扩展器,其高度设置为25.在两者之间有一个网格拆分器.我想做的是对扩展器的效果进行动画扩展/折叠,并使网格行与之一起进行动画处理,以使在行向上跳跃然后使扩展器动画标签稍微变一点时看起来并不傻一会儿之后.这是我在扩展器扩展事件中拥有的...
I have a grid with two rows. In the first row I have a canvas, in the second I have an expander with it's height set to 25. There is a Grid splitter between the two. What I would like to do is to animate the effects of the expander expanding/collapsing and have the grid row animate along with it so that it doesn't look goofy having having the row jump up and then have the expander animation tag along a little while after. This what I have in the expander expanded event...
DoubleAnimation dblAnimation = 新 DoubleAnimation ();
DoubleAnimation dblAnimation = new DoubleAnimation();
//设置我们希望扩展控件的高度
//set the height that we want the expander control to
//动画制作完成时具有
//have when animation is complete
dblAnimation.To = 150;
dblAnimation.To = 150;
//设置此动画的持续时间-通常最好是1/4或更小
//set the duration of this animation - generally 1/4 or less looks best
dblAnimation.Duration = 新 持续时间 ( TimeSpan .FromSeconds(.20));
dblAnimation.Duration = new Duration(TimeSpan.FromSeconds(.20));
//从高度属性上的动画开始
//begin the animation on the height property
MainGrid.RowDefinitions [2] .BeginAnimation( RowDefinition .HeightProperty,dblAnimation); ( 此行会炸掉,并显示错误消息... System.Windows.Media.Animation.DoubleAnimation类型的AnimationTimeline.不能用于为'System.Windows.GridLength'类型的'Height'属性设置动画)
MainGrid.RowDefinitions[2].BeginAnimation(RowDefinition.HeightProperty, dblAnimation); (This line blows up giving the error...AnimationTimeline of type 'System.Windows.Media.Animation.DoubleAnimation' cannot be used to animate the 'Height' property of type 'System.Windows.GridLength')
TaskExpander.BeginAnimation( Expander .HeightProperty,dblAnimation); (有效)
TaskExpander.BeginAnimation(Expander.HeightProperty, dblAnimation); (This works)
推荐答案
您需要为值"动画Height属性的属性.您可以通过将值绑定到窗口/面板中的属性,然后为该绑定的属性设置动画,或使用路径来获取结构的属性来实现此目的.您还必须使用单位构造函数将行高定义明确设置为GridLength.
http://msdn2.microsoft.com/zh-cn/library/ms557307.aspx
You need to animate the "value" attribute of the Height property. You can do this by binding the value to a property in your window/panel and then animating that bound property, or using a path to get to the attribute of the structure. You will also have to have the Height of the row definition set explicitly to a GridLength using the units constructor.
http://msdn2.microsoft.com/en-us/library/ms557307.aspx
这篇关于可以对RowDefinition进行动画处理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!