2011-02-08 8 views
1

ポップアップや向きに問題があることは知っています。私はポップアップが視覚的な木の中にあるならば、向きを尊重すべきだと読んだ。私は2つのタイプのポップアップを持っています.1つはグローバル(ビジュアルツリーではない)で、もう1つは特定のページxamlで定義されています。私はまだグローバルに取り組んでいませんが、私はそのページを特定のものにすることを望んでいました。WP7ビジュアルツリーのポップアップが向きを尊重しない

は、ここに私のXAMLです:

x:Class="Views.MainPanorama" 
    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:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" 
    xmlns:toolkitPrimitives="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls.Toolkit" 
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="800" 
    FontFamily="{StaticResource PhoneFontFamilyNormal}" 
    FontSize="{StaticResource PhoneFontSizeNormal}" 
    Foreground="{StaticResource PhoneForegroundBrush}" 
    SupportedOrientations="PortraitOrLandscape" 
    shell:SystemTray.IsVisible="False"> 

    <toolkit:TransitionService.NavigationInTransition> 
     <toolkit:NavigationInTransition> 
      <toolkit:NavigationInTransition.Backward> 
       <toolkit:TurnstileTransition Mode="BackwardIn"/> 
      </toolkit:NavigationInTransition.Backward> 
      <toolkit:NavigationInTransition.Forward> 
       <toolkit:TurnstileTransition Mode="ForwardIn"/> 
      </toolkit:NavigationInTransition.Forward> 
     </toolkit:NavigationInTransition> 
    </toolkit:TransitionService.NavigationInTransition> 
    <toolkit:TransitionService.NavigationOutTransition> 
     <toolkit:NavigationOutTransition> 
      <toolkit:NavigationOutTransition.Backward> 
       <toolkit:TurnstileTransition Mode="BackwardOut"/> 
      </toolkit:NavigationOutTransition.Backward> 
      <toolkit:NavigationOutTransition.Forward> 
       <toolkit:TurnstileTransition Mode="ForwardOut"/> 
      </toolkit:NavigationOutTransition.Forward> 
     </toolkit:NavigationOutTransition> 

<ScrollViewer x:Name="mainScroll"> 
    <Grid x:Name="LayoutRoot" Style="{StaticResource BackgroundStyle}"> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="*"/> 
     </Grid.RowDefinitions> 

     <Image x:Name="icon" Source="/Folder;component/Images/Icons/logo.png" Height="24" Width="175" HorizontalAlignment="Left" Margin="20, 15, 0, 0" /> 
     <controls:Panorama Name="panMain" HeaderTemplate="{StaticResource PanoramaHeaderTemplate}" Grid.Row="1" Margin="0, -10, 0, 0" Height="680"> 
      <!--Panorama definition here--> 
     </controls:Panorama> 
     <gbl:SecureFooter ShowLock="True" x:Name="panoFoot" Grid.Row="2" VerticalAlignment="Bottom" Margin="24, 24, 24, 0" /> 

     <Popup x:Name="_popup" Grid.Row="3" /> 
    </Grid> 
</ScrollViewer> 

ページの作品とポップアップが表示されますが、私は電話やエミュレータを回転させたときに、ポップアップの内容は、向きを変更しないでください。

私が使用してコード内でポップアップの内容を設定しています:

_popup.Child = new OneOfTwoPopupUserControls(); 

これは、ポップアップが向きを無視させることができますか?それがxamlで作成されたときにその中に完全な内容を入れる必要がありますか?

+0

あなた自身のポップアップを行うそれはそれを正しく処理する唯一の方法だと思われます。 –

+0

どういう意味ですか?私は自分のポップアップをやっている?私は、ユーザーコントロールを作成し、それらをポップアップで子として設定しています。 – CACuzcatlan

答えて

2

ポップアップはページのビジュアルツリーの外側にあります。ページはオリエンテーションの変更を処理するものなので、ポップアップ自体は影響を受けません。

私が作業した唯一の解決策は、向きが変わったイベントを聞いて、ポップアップコンテンツを自分自身で変換することです。理想的ではないし、私のためにうまくいきませんでした。結局私はポップアップを捨てました。

申し訳ありません、もっと助けていただけませんでした。

+0

残念ながら、あなたが正しいと思われます。私たちはあらゆる種類のものを試してきました。それを動かす唯一の方法は、手動で回転させることです。 – CACuzcatlan

5

あなたは次の行を使用して、ビジュアルツリーにポップアップを追加したい場合は、ポップアップが正しく回転:ポップアップ回転することが実際には非常にシンプル

LayoutRoot.Children.Add(popupInstance); 
+0

これは私のために働いた。ポップアップの前に行を追加するだけです。IsOpen = true;私は向きが変わってもポップアップを閉じる。 –

2

その - 正確であること、またはそのコンテンツを - に従ってオリエンテーションに。あなたがしなければならないのは、向きの変更...

static PhoneApplicationFrame ApplicationRootFrame 
{ 
    get { return ((PhoneApplicationFrame) Application.Current.RootVisual); } 
} 

ApplicationRootFrame.OrientationChanged += OnOrientationChanged 

に耳を傾け、以下のコードがするような何かをすることです。 TransformGroupは、ポップアップコンテンツがコンテンツの中心を中心に回転するようにします。

private static void ApplyOrientationTransform(PageOrientation orientation, FrameworkElement popupContent) 
{ 
    TransformGroup group; 

    switch (orientation) 
    { 
    case PageOrientation.LandscapeRight: 
     group = new TransformGroup(); 
     group.Children.Add(new TranslateTransform { X = -popupContent.ActualWidth/2, Y = -popupContent.ActualHeight/2 }); 
     group.Children.Add(new RotateTransform {CenterX = 0, CenterY = 0, Angle = -90}); 
     group.Children.Add(new TranslateTransform { X = popupContent.ActualWidth/2, Y = popupContent.ActualHeight/2 }); 
     popupContent.RenderTransform = group; 
     break; 
    case PageOrientation.LandscapeLeft: 
     group = new TransformGroup(); 
     group.Children.Add(new TranslateTransform { X = -popupContent.ActualWidth/2, Y = -popupContent.ActualHeight/2 }); 
     group.Children.Add(new RotateTransform {CenterX = 0, CenterY = 0, Angle = 90}); 
     group.Children.Add(new TranslateTransform { X = popupContent.ActualWidth/2, Y = popupContent.ActualHeight/2 }); 
     popupContent.RenderTransform = group; 
     break; 
    default: 
     popupContent.RenderTransform = null; 
     break; 
    } 
} 
0

私はもともとオリバーによって記載されているように、答えをしようと、私は表示しようとしていた情報については、変更する必要ポップアップのサイズを見つけました。私が抱えていた同様の問題を解決するために私はちょっと騙しました。再度showPopupメソッドを呼び出し、私はinfoPopup.IsOpen = falseを使用OrientationChanged方法で、その後

private void showPopup() 
    { 
     Session session = App.getSession(); 
     Template template = session.getTemplate(); 

     border.BorderBrush = new SolidColorBrush(Colors.White); 
     border.BorderThickness = new Thickness(2); 
     border.Margin = new Thickness(10, 10, 10, 10); 
     int initialMargin ; 
     int landMargin ; // margin for information if displayed in landscape orientation 
     StackPanel stkPnlOuter = new StackPanel(); 
     stkPnlOuter.Background = new SolidColorBrush(Colors.Black); 
     stkPnlOuter.Orientation = System.Windows.Controls.Orientation.Vertical; 
     stkPnlOuter.Tap += new EventHandler<System.Windows.Input.GestureEventArgs>(stkPnlOuter_Tap); 
     if (this.Orientation == PageOrientation.PortraitUp || this.Orientation == PageOrientation.PortraitDown) 
     { 
      initialMargin = 0; 
      landMargin = 0; 
     } 
     else 
     { 
      initialMargin = 5; 
      landMargin = 10; 
     } 

     TextBlock txt_blk1 = new TextBlock(); 
     txt_blk1.Text = "Loaded Type:"; 
     txt_blk1.TextAlignment = TextAlignment.Left; 
     txt_blk1.FontSize = 20; 
     txt_blk1.FontWeight = FontWeights.Bold; 
     txt_blk1.Margin = new Thickness(5, 5, 5, 5); 
     txt_blk1.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk2 = new TextBlock(); 
     txt_blk2.Text = template.templateType == TemplateType.TYPE.TEMPLATE_FILE ? "Valido Template File" : "Valido Assessment File"; 
     txt_blk2.TextAlignment = TextAlignment.Left; 
     txt_blk2.FontSize = 20; 
     txt_blk2.Margin = new Thickness(5,initialMargin, 5, initialMargin); 
     txt_blk2.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk3 = new TextBlock(); 
     txt_blk3.Text = "Template Type:"; 
     txt_blk3.TextAlignment = TextAlignment.Left; 
     txt_blk3.FontSize = 20; 
     txt_blk3.FontWeight = FontWeights.Bold; 
     txt_blk3.Margin = new Thickness(5, 10, 5, 5); 
     txt_blk3.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk4 = new TextBlock(); 
     txt_blk4.Text = TemplateClassification.getName(); 
     txt_blk4.TextAlignment = TextAlignment.Left; 
     txt_blk4.FontSize = 20; 
     txt_blk4.Margin = new Thickness(5, landMargin, 5, initialMargin); 
     txt_blk4.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk5 = new TextBlock(); 
     txt_blk5.Text = "Client Reference:"; 
     txt_blk5.TextAlignment = TextAlignment.Left; 
     txt_blk5.FontWeight = FontWeights.Bold; 
     txt_blk5.FontSize = 20; 
     txt_blk5.Margin = new Thickness(5, 10, 5, 5); 
     txt_blk5.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk6 = new TextBlock(); 
     txt_blk6.Text = template.ClientRef == null ? "-" : template.ClientRef; 
     txt_blk6.TextAlignment = TextAlignment.Left; 
     txt_blk6.FontSize = 20; 
     txt_blk6.Margin = new Thickness(5, landMargin, 5, initialMargin); 
     txt_blk6.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk7 = new TextBlock(); 
     txt_blk7.Text = "Template Code:"; 
     txt_blk7.TextAlignment = TextAlignment.Left; 
     txt_blk7.FontWeight = FontWeights.Bold; 
     txt_blk7.FontSize = 20; 
     txt_blk7.Margin = new Thickness(5, 10, 5, 5); 
     txt_blk7.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk8 = new TextBlock(); 
     txt_blk8.Text = template.Code; 
     txt_blk8.TextAlignment = TextAlignment.Left; 
     txt_blk8.FontSize = 20; 
     txt_blk8.Margin = new Thickness(5, landMargin, 5, initialMargin); 
     txt_blk8.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk9 = new TextBlock(); 
     txt_blk9.Text = "Template Title:"; 
     txt_blk9.TextAlignment = TextAlignment.Left; 
     txt_blk9.FontWeight = FontWeights.Bold; 
     txt_blk9.FontSize = 20; 
     txt_blk9.Margin = new Thickness(5, 10, 5, 5); 
     txt_blk9.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk10 = new TextBlock(); 
     txt_blk10.Text = template.Title; 
     txt_blk10.TextAlignment = TextAlignment.Left; 
     txt_blk10.FontSize = 20; 
     txt_blk10.Margin = new Thickness(5, landMargin, 5, initialMargin); 
     txt_blk10.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk11 = new TextBlock(); 
     txt_blk11.Text = "Modified Date:"; 
     txt_blk11.TextAlignment = TextAlignment.Left; 
     txt_blk11.FontWeight = FontWeights.Bold; 
     txt_blk11.FontSize = 20; 
     txt_blk11.Margin = new Thickness(5, 10, 5, 5); 
     txt_blk11.Foreground = new SolidColorBrush(Colors.White); 

     TextBlock txt_blk12 = new TextBlock(); 
     txt_blk12.Text = Valido_CA.modCommon.DateFromString(template.ModifiedDate); 
     txt_blk12.TextAlignment = TextAlignment.Left; 
     txt_blk12.FontSize = 20; 
     txt_blk12.Margin = new Thickness(5, landMargin, 5, 5); 
     txt_blk12.Foreground = new SolidColorBrush(Colors.White); 

     if (this.Orientation == PageOrientation.PortraitUp || this.Orientation == PageOrientation.PortraitDown) 
     { 


      stkPnlOuter.Children.Add(txt_blk1); 
      stkPnlOuter.Children.Add(txt_blk2); 
      stkPnlOuter.Children.Add(txt_blk3); 
      stkPnlOuter.Children.Add(txt_blk4); 
      stkPnlOuter.Children.Add(txt_blk5); 
      stkPnlOuter.Children.Add(txt_blk6); 
      stkPnlOuter.Children.Add(txt_blk7); 
      stkPnlOuter.Children.Add(txt_blk8); 
      stkPnlOuter.Children.Add(txt_blk9); 
      stkPnlOuter.Children.Add(txt_blk10); 
      stkPnlOuter.Children.Add(txt_blk11); 
      stkPnlOuter.Children.Add(txt_blk12); 
     } 
     else 
     { 
      StackPanel stkPnlLeft = new StackPanel(); 
      stkPnlLeft.Orientation = System.Windows.Controls.Orientation.Vertical; 
      stkPnlLeft.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; 
      StackPanel stkPnlRight = new StackPanel(); 
      stkPnlRight.Orientation = System.Windows.Controls.Orientation.Vertical; 
      stkPnlRight.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; 

      stkPnlOuter.Orientation = System.Windows.Controls.Orientation.Horizontal; 

      stkPnlLeft.Children.Add(txt_blk1); 
      stkPnlRight.Children.Add(txt_blk2); 
      stkPnlLeft.Children.Add(txt_blk3); 
      stkPnlRight.Children.Add(txt_blk4); 
      stkPnlLeft.Children.Add(txt_blk5); 
      stkPnlRight.Children.Add(txt_blk6); 
      stkPnlLeft.Children.Add(txt_blk7); 
      stkPnlRight.Children.Add(txt_blk8); 
      stkPnlLeft.Children.Add(txt_blk9); 
      stkPnlRight.Children.Add(txt_blk10); 
      stkPnlLeft.Children.Add(txt_blk11); 
      stkPnlRight.Children.Add(txt_blk12); 

      stkPnlOuter.Children.Add(stkPnlLeft); 
      stkPnlOuter.Children.Add(stkPnlRight); 
     } 

     StackPanel stkPnlInner = new StackPanel(); 
     stkPnlInner.Orientation = System.Windows.Controls.Orientation.Horizontal; 
     stkPnlInner.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; 

     Button btn_OK = new Button(); 
     btn_OK.Content = "OK"; 
     btn_OK.Width = 100; 
     btn_OK.Click += new RoutedEventHandler(btn_OK_Click); 



     stkPnlInner.Children.Add(btn_OK); 
     stkPnlInner.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; 

     stkPnlOuter.Children.Add(stkPnlInner); 

     border.Child = stkPnlOuter; 
     if (this.Orientation == PageOrientation.PortraitUp || this.Orientation == PageOrientation.PortraitDown) 
     { 
      border.Width = 350; 
      border.Height = 500; 
      transforBorder(border); 
      infoPopup.Child = border; 

      infoPopup.IsOpen = true; 
      infoPopup.VerticalOffset = (this.ActualHeight - border.Height)/2; 
      infoPopup.HorizontalOffset = (this.ActualWidth - border.Width)/2; 
     } 
     else 
     { 

      border.Width = 600; 
      border.Height = 350; 
      transforBorder(border); 
      infoPopup.Child = border; 
      infoPopup.IsOpen = true; 
      infoPopup.HorizontalOffset = (this.ActualHeight - border.Width)/2; 
      infoPopup.VerticalOffset = (this.ActualWidth - border.Height)/2; 
     } 



    } 

当初、私はshowPopup方法で計算し、ポップアップレンダリングのすべてを持っていました。

おそらくやや厄介な方法ですが、境界線の幅と高さを変更する必要があるため、これを簡単に実行できました。