Aqueel
Aqueel

Reputation: 1246

Popup orientation is not correct. Its 90 degrees rotated

Hi I have created a popup using Popup class in silverlight. I wrote a class of type UserControl and I added this usercontrol to the popup by using Child method of Popup class.

Following is the XAML code of my UserControl class

<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>

I set this PopupWindowContent to my popup using following code in my xaml file

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

Problem is that when I execute this code, popup orientation is according to portrait but my app is landscape. So popup looks 90 degrees rotated. Can anyone please tell me how can i fix it?

Best Regards

Upvotes: 0

Views: 864

Answers (4)

Ajeun
Ajeun

Reputation: 21

I found that if you put the popup into the xaml code of the page, then the orientation is done properly.

Upvotes: 2

Tuomas Hautakangas
Tuomas Hautakangas

Reputation: 31

Do not rotate the popup but place a border inside the popup and load the content in the border.

I got it to work like this:

//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;

Upvotes: 0

CACuzcatlan
CACuzcatlan

Reputation: 5497

I've seen some suggestions of adding the popup to the visual tree. I tried adding it to my xaml and it still didn't rotate, but you might want to give it a shot.

Upvotes: 0

John Gardner
John Gardner

Reputation: 25126

Are you setting SupportedOrientation on every page of your app or just the first? I think there's a wierd thing that if you set it on your first page, some things will respect it, but others (like the popup) look at the supported orientations of the active page?

Upvotes: 0

Related Questions