private void OnOrientationChanged(object sender, OrientationChangedEventArgs args)
{
// margin for shifting ad panel when in landscape mode
// the margin is equal to (width - height)/2 = (480 - 80)/2 = 200
const int margin = 200;
// initial value of the margin of the page. If the SystemTray has an opacity
// we need to shift the page content over
Thickness pageMargin = _page.Margin;
// margin use when rotating the ad
Thickness rotateMargin = new Thickness(0, 0, 0, 0);
// angle to rotate the ad (if in landscape)
double angle = 0;
int rotateRow = 0;
int rotateRowspan = 0;
int rotateColumn = 0;
switch (args.Orientation)
{
case PageOrientation.None:
break;
case PageOrientation.Portrait:
case PageOrientation.PortraitUp:
case PageOrientation.PortraitDown:
rotateRow = 2;
rotateColumn = 1;
rotateRowspan = 1;
if ((SystemTray.Opacity > 0) && (SystemTray.Opacity < 1))
{
pageMargin = new Thickness(0, 32, 0, 0);
}
break;
case PageOrientation.Landscape:
case PageOrientation.LandscapeRight:
rotateRowspan = _rootGrid.RowDefinitions.Count;
rotateMargin = new Thickness(-margin, 0, -margin, 0);
angle = 90;
if ((SystemTray.Opacity > 0) && (SystemTray.Opacity < 1))
{
pageMargin = new Thickness(0, 0, 72, 0);
}
break;
case PageOrientation.LandscapeLeft:
rotateRowspan = _rootGrid.RowDefinitions.Count;
rotateColumn = 2;
rotateMargin = new Thickness(-margin, 0, -margin, 0);
angle = -90;
if ((SystemTray.Opacity > 0) && (SystemTray.Opacity < 1))
{
pageMargin = new Thickness(72, 0, 0, 0);
}
break;
default:
throw new ArgumentOutOfRangeException();
}
_page.Margin = pageMargin;
// now set location and rotation of ad panel
_stationaryPanel.Margin = rotateMargin;
((RotateTransform)_stationaryPanel.RenderTransform).Angle = angle;
Grid.SetRow(_stationaryPanel, rotateRow);
Grid.SetColumn(_stationaryPanel, rotateColumn);
Grid.SetRowSpan(_stationaryPanel, rotateRowspan);
}