Answer the question
In order to leave comments, you need to log in
How to make animated image switching in WPF?
I just can not figure out how to make a smooth transition from one picture to another. There are 4 pictures, they are filled in List<>. The image is located on the form, the image is displayed in it, how to make a smooth smooth transition between the pictures.
Answer the question
In order to leave comments, you need to log in
Use triggers:
In XAML:
<Image Source="{Binding CurrentImage}" >
<Image.Triggers>
<EventTrigger RoutedEvent="Image.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="(Image.Opacity)" From="0" To="1" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Image.Triggers>
</Image>
<Button Content="Next image" MouseLeftButtonDown="NextImageClick"/>
public BitmapImage CurrentImage { get; set; }
public List<BitmapImage> Images { get; set; }
private int _imageIndex = 0;
public void NextImageClick(object sender, MouseButtonEventArgs e)
{
if (_imageIndex >= Images.Count) _imageIndex = 0;
CurrentImage = Images[imageIndex];
RaisePropertyChanged("CurrentImage"); //необходимо реализовать INotifyPropertyChanged в классе модели
_imageIndex++;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question