public void AnimateOrientationChange(OrientationChangedEventArgs e)
{
// check if new orientation is landscape or portrait
if (e.Orientation == PageOrientation.Landscape || e.Orientation == PageOrientation.LandscapeLeft || e.Orientation == PageOrientation.LandscapeRight) {
// if landscape dimensions were not calculated we must do it now
if (!mAnimationInitialized) {
// calculate landscape box size based on screen size
mLandscapeWidth = ActualWidth * kLandscapeRatio;
mLandscapeHeight = mLandscapeWidth * kAspectRatio;
// set animation values for both animations (landcape to portrait and reverse)
mP2LWidthAnimation.From = mPortraitHeight;
mP2LWidthAnimation.To = mLandscapeWidth;
mP2LHeightAnimation.From = mPortraitWidth;
mP2LHeightAnimation.To = mLandscapeHeight;
mL2PWidthAnimation.From = mLandscapeHeight;
mL2PWidthAnimation.To = mPortraitWidth;
mL2PHeightAnimation.From = mLandscapeWidth;
mL2PHeightAnimation.To = mPortraitHeight;
// mark animation as initialized and ready
mAnimationInitialized = true;
}
// start portrait to landscape animation
mP2LAnimation.Begin();
} else {
// start landscape to portrait animation if all values are calculated
if (mAnimationInitialized) {
mL2PAnimation.Begin();
}
}
}