wp7奇怪的行为改变方向

时间:2011-12-01 08:46:07

标签: windows-phone-7 orientation

在我的应用更改方向时出现问题。该应用程序很简单,只有一个网格(“contentpanel”) 带有边距和称为“包装器”的嵌套网格,具有恒定的20px边距。

包装器的宽度应为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 个答案:

答案 0 :(得分:1)

在您的事件处理程序中,您的控件尚未调整大小。您收到OLD尺寸。 Dispatcher一切都适合我:

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