我想要创建图像的幻灯片。为此,我在每次设定的时间间隔后在图像控制中加载了新图像。但每次我加载一个新的图像它没有任何动画,我需要加载每个图像与过渡动画或淡入淡出动画。在Image控件中更改图像时如何实现动画?以下是代码:当在图像控件中加载时动画图像
XAML:
<Grid>
<Image Source="{Binding CurrentImage}" />
</Grid>
XAML.cs
ViewModel = new ScreenSaverViewModel();
this.DataContext = ViewModel;
ViewModel.cs
/// <summary>
/// Gets the current image to display on the attract screen. Changes to this property
/// cause the PropertyChanged event to be signaled
/// </summary>
public string CurrentImage
{
get { return this.currentImage; }
protected set
{
this.currentImage = value;
this.OnPropertyChanged("CurrentImage");
}
}
/// <summary>
/// Gets the observable collection of all images.
/// </summary>
public ObservableCollection<string> Images
{
get { return this.images; }
}
public ScreenSaverViewModel()
{
images = new ObservableCollection<string>();
this.LoadSlideShowImages();
if (Images != null && Images.Count > 0)
{
this.CurrentImage = this.Images[this.currentIndex];
this.tickTimer = new DispatcherTimer();
this.tickTimer.Interval = TimeSpan.FromMilliseconds(TimerIntervalMilliseconds);
this.tickTimer.Tick += (s, e) =>
{
this.currentIndex++;
this.currentIndex = this.currentIndex < this.Images.Count ? this.currentIndex : 0;
this.CurrentImage = this.Images[this.currentIndex];
};
// start the timer after image is loaded
this.tickTimer.Start();
}
}
使用故事板http://stackoverflow.com/questions/11073573/how-do-i-create-a-rotate-animation-on-an-image-object-using- c-sharp-code-only-i – Sajeetharan
但是,我将如何在新图像的变化上动画?意味着它应该看起来像新的图像加载动画。 –
你可以有两个覆盖图像。淡入顶部图像,设置底部图像,淡出顶部图像,设置顶部图像,重复。 另外[this](http://stackoverflow.com/questions/1165862/animate-wpf-text-when-binding-updates-how)可能会有所帮助。 – DamenEU