弹出方向不正确。它旋转90度

时间:2010-10-27 12:29:16

标签: silverlight popup windows-phone-7

您好 我在Silverlight中使用Popup类创建了一个弹出窗口。我写了一个类UserControl的类,我使用Popup类的Child方法将这个usercontrol添加到弹出窗口。

以下是我的UserControl类的XAML代码

<UserControl x:Class="MyProject.PopupWindowContent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"            
Foreground="{StaticResource PhoneForegroundBrush}" UseLayoutRounding="False" Cursor="Hand">

    <Grid Height="355" Name="grid1" Width="527.5">
        <Image Height="355" HorizontalAlignment="Left" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="527" Source="/MyProject;component/dialog_bg.png" UseLayoutRounding="True" />
        <Image Height="194" HorizontalAlignment="Left" Margin="13,87,0,0" Name="image2" Stretch="Fill" VerticalAlignment="Top" Width="502.5" Source="/MyProject;component/dialog_box_1.png" />
        <Image Height="46" HorizontalAlignment="Left" Margin="25.25,35.25,0,0" Name="image3" Stretch="Fill" VerticalAlignment="Top" Width="49.75" Source="/MyProject;component/dialog_logo.png" />
        <TextBlock Height="40" HorizontalAlignment="Left" Margin="153.25,38.75,0,0" Name="popupHeading" Text="TextBlock" VerticalAlignment="Top" Width="212" TextAlignment="Center" FontWeight="Bold" FontSize="26" />
    <Button Content="Submit" Height="71" HorizontalAlignment="Left" Margin="130.75,265.75,0,0" Name="buttonOne" VerticalAlignment="Top" Width="132.25" BorderThickness="1" FontSize="18" Foreground="Black">
            <Button.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="White" Offset="0" />
                    <GradientStop Color="#FF06EF06" Offset="1" />
                </LinearGradientBrush>
            </Button.Background>
        </Button>
        <Button BorderThickness="1" Content="Cancel" FontSize="18" Foreground="Black" Height="71" HorizontalAlignment="Right" Margin="0,265.75,142,0" Name="buttonTwo" VerticalAlignment="Top" Width="132.25">
            <Button.Background>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="White" Offset="0" />
                    <GradientStop Color="#FFEF0606" Offset="1" />
                </LinearGradientBrush>
            </Button.Background>
        </Button>
    <TextBox Height="162.75" HorizontalAlignment="Left" Margin="18,108.25,0,0" Name="popupBody" Text="TextBox" VerticalAlignment="Top" Width="480.5" Background="{x:Null}" FontSize="20" Foreground="White" BorderThickness="0" />
</Grid>

我使用xaml文件中的以下代码将此PopupWindowContent设置为弹出窗口

        Popup popUnWin = new Popup();
        popUnWin.Child = new PopupWindowContent();
        popUnWin.IsOpen = true;

问题是,当我执行此代码时,弹出方向是根据肖像,但我的应用程序是横向。所以popup看起来旋转了90度。 任何人都可以告诉我如何解决它?

最好的问候

4 个答案:

答案 0 :(得分:2)

我发现如果你把弹出窗口放到页面的xaml代码中,那么方向就会正确完成。

答案 1 :(得分:0)

您是在应用的每个页面上设置SupportedOrientation还是仅在第一个页面上设置{{1}}?我认为有一个奇怪的事情,如果你在第一页上设置它,有些事情会尊重它,但其他人(如弹出窗口)会查看活动页面支持的方向吗?

答案 2 :(得分:0)

我已经看到了一些将弹出窗口添加到可视树中的建议。我尝试将它添加到我的xaml中它仍然没有旋转,但你可能想试一试。

答案 3 :(得分:0)

不要旋转弹出窗口,而是在弹出窗口中放置边框并在边框中加载内容。

我让它像这样工作:

//In .xaml
<Popup x:Name="myPopup">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="480" />
        </Grid.RowDefinitions>

        <Border x:Name="popupBorder"/>
    </Grid>
</Popup>

//In .xaml.cs
popupBorder.Child = new MyPopupPage(); //MyPopupPage is the "Windows Phone Landscape Page"
myPopup.IsOpen = true;