如何检测方向变化并更改布局? [英] How to detect orientation changes and change layout?
问题描述
让我们说我有一个网格,其中包含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.
我对此有什么控制权?
thx
推荐答案
对于完整的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.
这篇关于如何检测方向变化并更改布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!