I have an animation which moves a grid to a specific place and then automatically goes back using AutoReverse. But since it's instant the user cannot read the message inside of it. How can I put a -for example- 5 seconds delay in the animation
Here is the method I have so far
public void ErrorMessage(Grid grid, ImageSource imageSource, String error_message)
{
Image_Broken_Component.Source = imageSource;
TextBlock_Error_Message.Text = error_message;
ThicknessAnimation ta = new ThicknessAnimation
{
From = grid.Margin,
To = new Thickness(0, 50, 0, 0),
Duration = new Duration(TimeSpan.FromSeconds(1)),
AutoReverse = true
};
grid.BeginAnimation(Grid.MarginProperty, ta);
}
The animation should play like this (using the From and To-values): 1 -> 0 -> wait 5s -> 1
Instead of using the
AutoReverseproperty, use aStoryboard:https://learn.microsoft.com/en-us/dotnet/framework/wpf/graphics-multimedia/storyboards-overview
The
BeginTimeproperty can be used to delay the second animation to do basic sequencing as seen here:XAML C# WPF Best efficient way to do an ordered sequence of animations
Then you can just sequence two
ThicknessAnimations(one forward, one reverse) and set theBeginTimeof the second one so that there is a pause before the animation is reversed.Example code: