且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检测方向变化并更改布局?

更新时间:2022-05-25 08:54:44

对于完整的xaml解决方案,您应该使用xaml中的VisualStateManager:

You should make use of the VisualStateManager in xaml, for a full xaml solution:

<Grid x:Name="LayoutRoot">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="OrientationStates">
            <VisualState x:Name="Full"/>
            <VisualState x:Name="Fill"/>
            <VisualState x:Name="Portrait"/>
            <VisualState x:Name="Snapped"/>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
</Grid>

为每个VisualState创建StoryBoard,并在xaml中隐藏/显示元素. Microsoft示例使用相同的解决方案.

Create StoryBoards for each VisualState and hide/show elements in your xaml. Microsoft examples use the same solution.

-

更新

我搜索了网络并找到了正确的状态,此链接后面有一个示例:

I searched the net and found the proper states, an example is behind this link: MSDN.

 <VisualStateManager.VisualStateGroups>
     <VisualStateGroup x:Name="ApplicationViewStates">
        <VisualState x:Name="FullScreenLandscape"/>
        <VisualState x:Name="Filled"/>
        <VisualState x:Name="FullScreenPortrait"/>
        <VisualState x:Name="Snapped"/>
    </VisualStateGroup>
 </VisualStateManager.VisualStateGroups>

状态反映了 ApplicationViewState 枚举.甚至可以在此处找到更多信息.

The states reflect the ApplicationViewState enum. Even more information can be found here.