2011-12-01 56 views
1

。該應用程序是簡單的,只需格柵(「的ContentPanel」) 具有餘量和稱爲「包裝」嵌套網格,具有恆定20像素餘量。WP7奇怪的行爲改變方向

包裝的寬度應728px - 20px *2 = 688

但是,當我切換到縱向,然後回到橫向時, 儘管沒有任何更改,但寬度現在是728px。

圖片: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; 
} 

回答

1

在事件處理程序的控制還沒有調整。您會收到OLD大小。使用Dispatcher所有適合我:

Dispatcher.BeginInvoke(() => 
{ 
    uiDebug.Text = "h:" + uiWrapper.RenderSize.Height + " l: " + uiWrapper.RenderSize.Width; 
}); 
+0

真的真的謝謝你!!!!!! – LXG