可视化树中的 WP7 弹出窗口不尊重方向

发布于 2024-10-16 15:00:33 字数 3622 浏览 3 评论 0原文

我知道弹出窗口和方向存在问题。我读过,如果弹出窗口位于视觉树中,它应该尊重方向。我有两种类型的弹出窗口,一种是全局的(不在可视化树中),另一种是在特定页面 xaml 上定义的。我还没有抽出时间来处理全局问题,但我希望能让特定页面正常工作。

这是我的 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 中创建时是否需要包含完整内容?

I know there are issues with popups and orientation. I've read that if a popup is in the visual tree, it should respect the orientation. I have two types of popups, one global (not in the visual tree) and one that is defined on a specific page xaml. I haven't gotten around to dealing with the global yet, but I was hoping to get the page specific one working.

Here is my 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>

The page works and the popup appears, but when I rotate the phone or emulator, the contents of the popup don't change orientation.

I'm setting the contents of the popup in code using:

_popup.Child = new OneOfTwoPopupUserControls();

Could this be causing the popup to ignore orientation? Does it need to have the full contents inside it when it's created in the xaml?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

纵山崖 2024-10-23 15:00:34

如果要将 Popup 添加到可视化树,请使用以下行,Popup 会正确旋转:

LayoutRoot.Children.Add(popupInstance);

If you want to add the Popup to the visual tree, use the following line, the Popup rotates correctly:

LayoutRoot.Children.Add(popupInstance);
风渺 2024-10-23 15:00:34

据我了解,弹出窗口位于页面的可视树之外,因为页面是处理方向更改的,所以弹出窗口本身不受影响。

我使用过的唯一解决方案是监听方向更改事件并对弹出内容进行我自己的转换。不理想,对我来说效果不佳。最后我放弃了Popup。

抱歉我无法提供更多帮助。

From what I understand Popup lives outside the visual tree of the Page, since the Page is what handles the Orientation changes the Popup itself is not affected.

The only solution I've worked with is listening to the orientation changed events and doing my own transform of the popup contents. Not ideal and didn't work well for me. In the end I discarded the Popup.

Sorry I couldn't be more help.

往昔成烟 2024-10-23 15:00:34

根据方向旋转弹出窗口(或者准确地说是其内容)实际上非常简单。您所要做的就是监听方向变化...

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

ApplicationRootFrame.OrientationChanged += OnOrientationChanged

并执行如下代码所示的操作。 TransformGroup 确保 Popup 内容围绕内容中心旋转。

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

Its actually quite simple to rotate the Popup - or its content to be precise - according to orientation. All you have to do is to listen to Orientation changes ...

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

ApplicationRootFrame.OrientationChanged += OnOrientationChanged

And do something like the code below does. The TransformGroup ensures that the Popup content is rotated around the center of the content.

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;
  }
}
夏天碎花小短裙 2024-10-23 15:00:34

我最初确实尝试了奥利弗所描述的答案,但发现弹出窗口的大小需要更改以适应我试图显示的信息。我做了一些作弊来完成我遇到的类似问题。

最初,我在 showPopup 方法中计算了所有弹出窗口渲染:

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



    }

然后在 OrientationChanged 方法中我使用了 infoPopup.IsOpen = false,然后再次调用 showPopup 方法。

这样做可能有点草率,但因为我需要更改边框的宽度和高度,所以我发现完成任务很简单。

I did originally try the answer as described by Oliver, but found the sizing of the popup needed changing for the information I was trying to display. I cheated a little to complete a similar issue I was having.

Initially I had all of the popup rendering calculated in the showPopup method:

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



    }

then in the OrientationChanged method I used the infoPopup.IsOpen = false, then called the showPopup method again.

Possibly a slightly sloppy way of doing this, but because I needed to change the width and height of the border I found this a simple was to complete the task.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文