using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
namespace Animation
public partial class MainWindow : Window
public MainWindow()
InitializeComponent();
private void btnChangeImage_Click(object sender, RoutedEventArgs e)
DoubleAnimation fadeIn = new DoubleAnimation
From = 0,
To = 1,
Duration = TimeSpan.FromSeconds(2)
DoubleAnimation fadeOut = new DoubleAnimation
From = 1,
Duration = TimeSpan.FromSeconds(2),
fadeOut.Completed += (o, e) =>
img.Source = new BitmapImage(new Uri(@"C:\images.jpg"));
img.BeginAnimation(OpacityProperty, fadeIn);
fadeIn.Completed += (o, e) =>
img.Source = new BitmapImage(new Uri(@"C:\images.jpg"));
img.BeginAnimation(OpacityProperty, fadeOut);
img.Source = new BitmapImage(new Uri(@"C:\images1.jpg"));
img.BeginAnimation(OpacityProperty, fadeIn);
}