A problem arise during orientation change for my app. The app is simple, with just a grid ("contentpanel") with a margin and a nested grid called "wrapper", with constant 20px margin.
The width of the wrapper should be 728px - 20px *2 = 688
.
However, when I switch to Portrait orientation, and then back to Landscape orientation, althought nothing is changed, the width is now 728px.
Image: http://imageshack.us/photo/my-images/713/15445549.jpg
XAML:
<phone:PhoneApplicationPage
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Class="ManipulationPhoto.TestPhoto2"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
shell:SystemTray.IsVisible="True">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="176"/>
<RowDefinition Height="592*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="uiDebug" Text="APPLICAZIONE" Style="{StaticResource PhoneTextNormalStyle}"/>
<Button Content="Button" Height="71" Name="button1" Width="160" Click="button1_Click" />
</StackPanel>
<Grid Background="AliceBlue" x:Name="ContentPanel" Grid.Row="1" Margin="0,0,0,0">
<Grid Name="uiWrapper" Background="Brown" Margin="20,20,20,20">
</Grid>
</Grid>
</Grid>
</phone:PhoneApplicationPage>
C#
public TestPhoto2()
{
InitializeComponent();
this.OrientationChanged += new EventHandler<OrientationChangedEventArgs>(TestPhoto2_OrientationChanged);
}
void TestPhoto2_OrientationChanged(object sender, OrientationChangedEventArgs e)
{
uiDebug.Text = "h:" + uiWrapper.RenderSize.Height + " l: " + uiWrapper.RenderSize.Width;
}