如何检测方向变化和改变布局? [英] How to detect orientation changes and change layout?

查看:16
本文介绍了如何检测方向变化和改变布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含 2 行、2 列和每个单元格内的许多控件的网格.

Lets say that I have a grid with 2 rows, 2 columns and many controls inside each cell.

当应用程序更改为快照模式时,我的意思是我希望应用程序只占屏幕的 1/3,一列,两行,并且只显示一些我会决定的控件.

When the application is changed to snap mode, I meant 1/3 of the screen I would like the application to be only, one Column, 2 rows and show only some controls I would decide.

对此我有什么样的控制权?

What kind of control do I have for this?

谢谢

推荐答案

您应该使用 xaml 中的 VisualStateManager,以获得完整的 xaml 解决方案:

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.

--

更新

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

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.

这篇关于如何检测方向变化和改变布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆