Home >

Animating ViewBox for WPF

2. August 2011

ViewBox (or more accurately Viewbox for those pedants playing along at home) is a nifty little convenience wrapper around scale transformations that is typically used to scale up content to fit a given area. Recently I wanted a Viewbox that animated on resize, and thus the AnimatingViewBox was born.

Essentially it allows you to specify an easing function for the resize, and a duration for the X and Y.

<Samples:AnimatingViewBox Grid.Row="1" Margin="20" 
         ResizeXDuration="0:0:0.5" ResizeYDuration="0:0:1">
	<Samples:AnimatingViewBox.EasingFunction>
		<BounceEase Bounces="1" Bounciness="0.6" />
	</Samples:AnimatingViewBox.EasingFunction>
	<TextBox Text="Test" AcceptsReturn="True" BorderThickness="0" />
</Samples:AnimatingViewBox>

Or you can just use it as a drop-in replacement for the Viewbox, in which case it defaults to about 300ms for the X and Y resize, and a BackEase.

The source code and sample application are available on bitbucket as part of my learnwpf samples project.

Here is the obligatory video

Comments (1) -

8/4/2011 2:42:46 PM #
Thanks for useful info! Really good post!

Pingbacks and trackbacks (3)+

Comments are closed