2010-10-27 49 views
0

嗨 我已經使用Silverlight中的Popup類創建了一個彈出窗口。我編寫了一個UserControl類,並通過使用Popup類的Child方法將此用戶控件添加到彈出窗口中。彈出方向不正確。它的90度旋轉

以下是我的用戶類的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文件

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

問題是這樣的PopupWindowContent設置爲我的彈出窗口,當我執行此代碼,彈出方向是根據肖像,但我的應用程序是風景。所以彈出看起來旋轉90度。 任何人都可以請告訴我如何解決它?

問候

回答

0

你要爲你的應用程序的每個頁面上SupportedOrientation或僅僅是第一?我認爲有一件奇怪的事情是,如果你在第一頁上設置它,有些事情會尊重它,但是其他的(如彈出窗口)查看活動頁面的支持方向?

+0

是的,我在正在顯示的彈出窗口的當前頁面上添加了SupportedOrientations =「Landscape」。我試着旋轉整個彈出。它的作品,但由於我在彈出窗口上有一個文本框,當我嘗試在這個彈出框中輸入內容時,鍵盤出現在縱向視圖中:-( – Aqueel 2010-10-29 11:36:47

0

我見過一些關於將彈出窗口添加到可視化樹的建議。我嘗試將它添加到我的xaml中,但它仍然沒有旋轉,但是您可能想要嘗試一下。

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

我發現,如果你把彈出到頁面的XAML代碼,然後定向做得好。