如何在WPF中逐渐(从无到有)成长图像

本文关键字:从无到有 成长 图像 WPF | 更新日期: 2023-09-27 18:01:25

所以,我正在用c#开发WPF中的应用程序,我想逐渐增长一个图像控件(使用DoubleAnimation)。我登了,但我的照片没有出现。下面是我的代码:

PACSCore.Height = 0; //Sets Image Size before enlarging
PACSCore.Width = 0;
DoubleAnimation anim = new DoubleAnimation(1, 0, (Duration)TimeSpan.FromSeconds(0.4)); //Creates DoubleAnimation
ScaleTransform st = new ScaleTransform(); //Creates ScaleTransform
st.ScaleX = 1; //Sets Scale for X and Y
st.ScaleY = 1;
PACSCore.RenderTransform = st;
st.BeginAnimation(ScaleTransform.ScaleXProperty, anim);
st.BeginAnimation(ScaleTransform.ScaleYProperty, anim);

如何在WPF中逐渐(从无到有)成长图像

感谢Clemens,我现在有了解决方案,并将其发布给其他人。我必须提前设置图像控件的大小,并使用DoubleAnimation将图像从0动画到1。下面是我的代码:

DoubleAnimation anim = new DoubleAnimation(0, 1, (Duration)TimeSpan.FromSeconds(1.2));
ScaleTransform st = new ScaleTransform();
st.ScaleX = 0;
st.ScaleY = 0;      
IMAGE.RenderTransform = st;
st.BeginAnimation(ScaleTransform.ScaleXProperty, anim);
st.BeginAnimation(ScaleTransform.ScaleYProperty, anim);