I want to animate my WPF window. It's set to size to content, so when the content changes, the window changes size. I don't want it to snap to a new size though, when it determines it needs a new size I want it to lerp between the old and new value with an animation.
How do I set this up?
EDIT: I am using SizeToContent=WidthAndHeight" as a parameter for my window, and want to animate when it automatically sizes to different content being shown.
On the Animations tab, in the Advanced Animation group, click Animation Pane. In the Animation Pane, select the animation that you want to trigger. In the Advanced Animation group, click Trigger, point to On Click of, and select the object that you want to trigger the animation.
When you want to click a specific thing on a slide to start an animation effect, use a trigger. Triggers give you specific click points for controlling animation, and are especially useful when you want several effects on a slide. Trigger an animation effect to begin when you click it.
The Element interface's animate() method is a shortcut method which creates a new Animation , applies it to the element, then plays the animation. It returns the created Animation object instance. Note: Elements can have multiple animations applied to them.
You may override the OnPropertyChanged
method and start an animation of any property you like.
For example, the Width property:
private DoubleAnimation widthAnimation;
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
if (e.Property == WidthProperty &&
!double.IsNaN((double)e.OldValue) &&
widthAnimation == null)
{
widthAnimation = new DoubleAnimation
{
Duration = TimeSpan.FromSeconds(1),
From = (double)e.OldValue,
To = (double)e.NewValue
};
widthAnimation.Completed += (s, a) =>
{
widthAnimation = null;
BeginAnimation(WidthProperty, null);
};
BeginAnimation(WidthProperty, widthAnimation);
}
else
{
base.OnPropertyChanged(e);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With