【发布时间】:2013-05-10 19:42:17
【问题描述】:
多年来我一直在编写 Android 应用程序,现在我正在开发 Windows Store/Windows 8 应用程序。
我很困惑如何为横向和纵向编写不同的屏幕布局。
在Android中,我们所要做的就是编写两种布局,一种用于纵向,另一种用于横向,遵循一些文件名的命名约定,当我们旋转设备时,平台会自动改变屏幕布局。
我一直在用谷歌搜索在我的 Windows 8 应用程序中执行相同操作的解决方案,我发现的只是使用 Visual State Groups 和 Visual States 的解决方案,在相同的 XAML 中对我们的小部件进行了一些修改当我们旋转设备时。
例如,当我将设备旋转到纵向时,让文本块改变其位置:
<VisualState x:Name="FullScreenPortrait" >
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Grid.ColumnSpan)" Storyboard.TargetName="GridViewTitle">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<x:Int32>3</x:Int32>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="GridViewTitle">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Thickness>0,10,10,807</Thickness>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
对我来说它看起来不是很干净和简单,即使使用 Visual Studio 的拖放小部件来生成代码的方法,我也觉得必须有一些比我更简单和更干净的解决方案做。
所以我的问题是:有没有更简单的解决方案来为每个方向编写 XAML 布局,还是我走对了,但很难走?
谢谢!
【问题讨论】:
标签: xaml windows-store-apps winrt-xaml