简体   繁体   English

旋转地铁风格

[英]Rotate metro style

I am playing with a Metro Style Application at the moment (.NET 4.5 RC [C#\\XAML], VS2012 RC) and I have one problem which I am unable to solve. 我目前正在使用Metro Metro应用程序(.NET 4.5 RC [C#\\ XAML],VS2012 RC),但有一个我无法解决的问题。

I would like to achieve that my app will change the layout when hosting device is rotated (+-45). 我希望实现当托管设备旋转(+ -45)时我的应用程序将更改布局。 I have prepared two layouts in XAML - one for landscape and second one for portrait, and I have done some animation for Visual States: 我已经在XAML中准备了两种布局-一种用于风景,另一种用于肖像,并且为视觉状态做了一些动画处理:

<VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="ApplicationViewStates">
        <VisualState x:Name="FullScreenLandscape"/>
        <VisualState x:Name="Filled"/>
        <VisualState x:Name="FullScreenPortrait">
            <Storyboard>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ControlContentLandscape" Storyboard.TargetProperty="Visibility">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed"/>
                </ObjectAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ControlContentPortrait" Storyboard.TargetProperty="Visibility">
                    <DiscreteObjectKeyFrame KeyTime="0" Value="Visible"/>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
        </VisualState>
        <VisualState x:Name="Snapped"/>
    </VisualStateGroup>
</VisualStateManager.VisualStateGroups>

But I do not know what to do next. 但是我不知道下一步该怎么做。 How to set my app that it will perform these animations when my device is turned into portrait mode? 如何将我的设备设置为纵向模式时将我的应用设置为执行这些动画?

I have analysed the Grid App template. 我已经分析了Grid App模板。 And I have noticed that the main page there inherits from the LayoutAwarePage class which is present in the Common folder. 而且我注意到那里的主页继承自Common文件夹中的LayoutAwarePage类。 The LayoutAwarePage class provide the handler for WindowSizeChanged event which is using the VisualStateManager to switch between states - this was the missing part in my current project. LayoutAwarePage类提供WindowSizeChanged事件的处理程序,该事件使用VisualStateManager在状态之间进行切换-这是我当前项目中缺少的部分。 The solution is: 解决方案是:

  1. Manually handle the WindowsSizeChanged event and use the VisualStateManager class and GoToState() method 手动处理WindowsSizeChanged事件,并使用VisualStateManager类和GoToState()方法
  2. Create new project (Grid App) and fit into it the current project. 创建一个新项目(Grid App)并使其适合当前项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM