在WinRT中包装的GridView方向

Vib*_*nRC 9 c# xaml gridview windows-runtime

我正在用c#开发一个WinRT应用程序,我使用GridView来呈现我的项目.

我希望我的项目水平排列然后(当达到最大宽度时)下一项应添加到新行(简单: 只能看到垂直滚动条).

不幸的是,我当前的xaml只能在一行中添加水平项目(带有水平滚动条)

<GridView x:Name="GridChildItem" 
                  ItemContainerStyle="{StaticResource NonTickGridViewItem}" 
                  VerticalContentAlignment="Stretch" 
                  ItemTemplate="{StaticResource CustomChildItemTemplete}"
                  SelectionMode="Single" 
                  IsItemClickEnabled="True" 
                  ItemClick="gridViewChild_ItemClick_1"
                  Margin="0,40,0,0" 
                  Height="Auto"
                  Background="{StaticResource DropDownMenuBackColor}" 
                  ScrollViewer.IsHorizontalScrollChainingEnabled="False"
                  ScrollViewer.IsVerticalScrollChainingEnabled ="True"
                  VerticalAlignment="Top">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <StackPanel Orientation="Horizontal" Margin="20,0,0,0" />
                </ItemsPanelTemplate>

           </GridView.ItemsPanel>
 </GridView>
Run Code Online (Sandbox Code Playgroud)

nem*_*esv 17

如果你不希望允许水平滚动,你需要使用ListView的替代GridView,

来自MSDN:

使用ListView显示垂直滚动的数据集合.要显示水平滚动的集合,请使用 GridView.

但是如果你想保持包装行为,你需要使用WrapGrid作为ItemsPanel:

<ListView>
     <ListView.ItemsPanel>
          <ItemsPanelTemplate>
                <WrapGrid Orientation="Horizontal" />
           </ItemsPanelTemplate>
     </ListView.ItemsPanel>
</ListView>
Run Code Online (Sandbox Code Playgroud)


Mar*_*l W 10

GridView的默认ItemsPanelTemplate包含一个Orientation ="Vertical"的WrapGrid:它堆叠垂直并滚动水平.

如果将"方向"更改为"水平",它将水平堆叠,但由于某种原因不会滚动.您可以通过在GridView上设置ScrollViewer.VerticalScrollMode ="Enabled"来解决这个问题(而不是在WrapGrid上!).

例:

<GridView ScrollViewer.VerticalScrollMode="Enabled">
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapGrid Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</GridView>
Run Code Online (Sandbox Code Playgroud)