Order items horizontal in XAML GridView (Win8 / Me

2020-06-05 05:49发布

how can i sort the items of GridView horizontal in the XAML? Sadly i found no method to achieve this. The Keyword "Orientation" is not available. Here is my current GridView:

            <GridView x:Name="TestDataBinding"
                HorizontalContentAlignment="Left"
                VerticalContentAlignment="Top"
                SelectionMode="None"
                ItemsSource="{Binding}"
                ItemTemplateSelector="{StaticResource itemTemplateSelector}"
                Margin="0,60,0,0"
                Width="1100" Height="540"
            />

Another Way could be a "VariableSizedWrapGrid". But this can't be used for creating Items through "ItemsSource" (and ItemTemplateSelector).

3条回答
欢心
2楼-- · 2020-06-05 06:32

Just set the orientation of the ItemsWrapGrid:

<GridView.ItemsPanel>
    <ItemsPanelTemplate>
        <ItemsWrapGrid Orientation="Horizontal"/>
    </ItemsPanelTemplate>
</GridView.ItemsPanel>
查看更多
等我变得足够好
3楼-- · 2020-06-05 06:40

Sorry, I have to take issue with your comment that this cannot be done with a VariableSizedWrapGrid. It most certainly can:

<GridView>
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <VariableSizedWrapGrid Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
    <x:String>One</x:String>
    <x:String>Two</x:String>
    <x:String>Three</x:String>
    <x:String>Four</x:String>
</GridView>

And I have to take issue that VariableSizedWrapGrid cannot be used for creating items through ItemsSource. It most certainly can. WrapGrid and VariableSizedWrapGrid are fundamentally identical. WrapGrid is slightly lighter weight since it does not support Column and Row spanning.

查看更多
贪生不怕死
4楼-- · 2020-06-05 06:51

Add an ItemsPanelTemplate to control how the items are arranged, for instance,

<GridView.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapGrid Orientation="Horizontal"/>
    </ItemsPanelTemplate>
</GridView.ItemsPanel>
查看更多
登录 后发表回答