2013-10-31 54 views

回答

12

你可以写,通过动画的Opacity属性设置为0淡出图像的扩展方法,然后设置Source财产并最终动画的不透明度回到1.

public static void ChangeSource(
    this Image image, ImageSource source, TimeSpan fadeOutTime, TimeSpan fadeInTime) 
{ 
    var fadeInAnimation = new DoubleAnimation(1d, fadeInTime); 

    if (image.Source != null) 
    { 
     var fadeOutAnimation = new DoubleAnimation(0d, fadeOutTime); 

     fadeOutAnimation.Completed += (o, e) => 
     { 
      image.Source = source; 
      image.BeginAnimation(Image.OpacityProperty, fadeInAnimation); 
     }; 

     image.BeginAnimation(Image.OpacityProperty, fadeOutAnimation); 
    } 
    else 
    { 
     image.Opacity = 0d; 
     image.Source = source; 
     image.BeginAnimation(Image.OpacityProperty, fadeInAnimation); 
    } 
} 
+0

非常感谢。该方法非常有用。非常感谢。 –

0

你可以使用这个WPF过渡,请在Here

+0

我只是想淡出效果和这个过渡有随机效应,这对我不好 –