我想要創建圖像的幻燈片。爲此,我在每次設定的時間間隔後在圖像控制中加載了新圖像。但每次我加載一個新的圖像它沒有任何動畫,我需要加載每個圖像與過渡動畫或淡入淡出動畫。在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