在WPF中使用动画从一个点到另一个点移动列表框 [英] Moving Listbox from one point to point with animation in WPF
本文介绍了在WPF中使用动画从一个点到另一个点移动列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用wpf将带有动画的列表框从一个点移动到另一点.用一定秒数的动画更改列表框的位置.我尝试了PointAnimation,但不知道如何将其设置为Listbox.如果您知道,请帮助我.谢谢.
Hi,
I want to move a listbox from one point to another point with animation using wpf. To change the location of listbox with animation of certain second. I tried PointAnimation, but don''t know how to set that to Listbox. If you know please help me in it. Thank you.
推荐答案
尝试两个DoubleAnimation
,一个用于Height
,另一个用于Left
.如果您已经稍微了解情节提要,这应该足以使您继续前进.
Try twoDoubleAnimation
, one for theHeight
and one for theLeft
. This should be enough to get you going if you already somewhat understand storyboards.
TranslateTransform trs = new TranslateTransform();
DoubleAnimation anim2 =新的DoubleAnimation(0,0,TimeSpan.FromSeconds(2));
DoubleAnimation anim3 =新的DoubleAnimation(0,listbox1.Margin.Left + 50,TimeSpan.FromSeconds(2));
trs.BeginAnimation(TranslateTransform.YProperty,anim2);
trs.BeginAnimation(TranslateTransform.XProperty,anim3);
listbox1.RenderTransform = trs;
TranslateTransform trs = new TranslateTransform();
DoubleAnimation anim2 = new DoubleAnimation(0, 0, TimeSpan.FromSeconds(2));
DoubleAnimation anim3 = new DoubleAnimation(0,listbox1.Margin.Left+50, TimeSpan.FromSeconds(2));
trs.BeginAnimation(TranslateTransform.YProperty, anim2);
trs.BeginAnimation(TranslateTransform.XProperty, anim3);
listbox1.RenderTransform = trs;
这篇关于在WPF中使用动画从一个点到另一个点移动列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文