Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WPF中逐渐(从无到有)增长图像_C#_Wpf_Doubleanimation - Fatal编程技术网

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

C# 如何在WPF中逐渐(从无到有)增长图像,c#,wpf,doubleanimation,C#,Wpf,Doubleanimation,因此,我正在用C#在WPF中开发一个应用程序,我希望逐渐增加一个图像控件(使用双动画)。我运行了它,但我的图像从未出现过。这是我的密码: PACSCore.Height = 0; //Sets Image Size before enlarging PACSCore.Width = 0; DoubleAnimation anim = new DoubleAnimation(1, 0, (Duration)TimeSpan.FromSeconds(0.4)); //Creates DoubleAn

因此,我正在用C#在WPF中开发一个应用程序,我希望逐渐增加一个图像控件(使用双动画)。我运行了它,但我的图像从未出现过。这是我的密码:

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);
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);

多亏了克莱门斯,我现在有了解决方案,并且为了其他人的利益发布了它。首先,我必须提前设置图像控件的大小,并使用DoubleAnimation将图像从0设置为1。这是我的密码:

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);
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);

“0到1之间的值会减小缩放对象的宽度;大于1的值会增大缩放对象的宽度。值1表示对象未在x方向缩放。”@GuillaumeBeauvois那么我应该如何设置它以达到正确的大小?这是另一个问题,我不知道,从未使用过它。但有一点是肯定的,不要将图像大小设置为(0,0),至少要将其设置为(1,1)。因为从0开始的缩放长度和宽度将始终为0。( ∞ * 0=0)最初将图像控件的宽度和高度设置为所需的最终值,或者根本不设置它们。因此,图像将具有其“自然”大小,该大小由其父容器或加载图像的大小定义。然后,将初始ScaleX和ScaleY值设置为0的ScaleTransform设置为1,并通过
new DoubleAnimation(1,TimeSpan.FromSeconds(0.4))
@Clemens感谢您的提示!成功了!