簡體   English   中英

在WinRT中包裝的GridView方向

[英]GridView Orientation with Wrapping in WinRT

我正在用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>

如果您不想允許水平滾動,則需要使用ListView而不是GridView

來自MSDN:

使用ListView顯示垂直滾動的數據集合。 要顯示水平滾動的集合,請使用GridView

但是,如果你想保持你需要使用包裝行為WrapGrid作為ItemsPanel

<ListView>
     <ListView.ItemsPanel>
          <ItemsPanelTemplate>
                <WrapGrid Orientation="Horizontal" />
           </ItemsPanelTemplate>
     </ListView.ItemsPanel>
</ListView>

GridView的默認ItemsPanelTemplate包含一個Orientation =“Vertical”的WrapGrid:它堆疊垂直並滾動水平。

如果將“方向”更改為“水平”,它將水平堆疊,但由於某種原因不會滾動。 您可以通過在GridView上設置ScrollViewer.VerticalScrollMode =“Enabled”來解決這個問題(而不是在WrapGrid上!)。

例:

<GridView ScrollViewer.VerticalScrollMode="Enabled">
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapGrid Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</GridView>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM