如何在旋转设备时更改GridView的ItemsPanelTemplate?
问题描述:
我有一个GridView与一个ItemsStackPanel,我想改变设备旋转时的方向。例如,如果ItemsPanelTemplate被定义为这样:如何在旋转设备时更改GridView的ItemsPanelTemplate?
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel GroupPadding="0,0,70,0" Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
我想以编程方式把它变成这样:
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsStackPanel GroupPadding="0,0,70,0" Orientation="Vertical"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
我无法弄清楚如何直接访问该对象。
答
最好的方法是创建两个您要使用的视图。看一下Visual Studio 2012提供的“Grid App”模板。它有一个GridView和一个ListView。当设备被捕捉时隐藏GridView并通过VisualState显示ListView