【问题标题】:WP7 allow orientation change but not the background imageWP7 允许改变方向但不允许背景图像
【发布时间】:2012-03-20 17:47:47
【问题描述】:

我的应用程序计划允许更改方向,但是,我有不想更改方向的背景图像(在允许用户更改背景图像的枢轴控件中)。我应该如何实现它?

感谢您的建议。

【问题讨论】:

    标签: windows-phone-7


    【解决方案1】:

    当方向改变时,您也许可以动态添加旋转变换以抵消背景图像的旋转,如下所示:-

            private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
        {
            if (e.Orientation == PageOrientation.PortraitUp)
            {
                PivotBackground.RelativeTransform = null;
            }
            else
            {
                RotateTransform aRotateTransform = new RotateTransform();
                aRotateTransform.CenterX = 0.5; 
                aRotateTransform.CenterY = 0.5;
                aRotateTransform.Angle = 90;
                PivotBackground.RelativeTransform = aRotateTransform;
            }
        }
    

    XAML 定义为:-

            <controls:Pivot Title="MY APPLICATION">
            <controls:Pivot.Background>
                <ImageBrush ImageSource="/Back.jpg"
                            x:Name="PivotBackground">
                </ImageBrush>
            </controls:Pivot.Background>
        </controls:Pivot>
    

    希望这会有所帮助。

    保罗·迪斯顿

    【讨论】:

    • 如果你想在你的应用程序中显示 SystemTray,上面可能会有一个小问题,因为随着方向的变化,SystemTray 会旋转并且需要稍大的宽度,因此会稍微移动背景图像。如果您禁用 SystemTray,则不会发生这种转变。
    猜你喜欢
    • 1970-01-01
    • 2013-06-12
    • 2020-12-18
    • 2018-06-15
    • 1970-01-01
    • 2012-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多