Order items horizontal in XAML GridView (Win8 / Metro)

試著忘記壹切 提交于 2019-12-21 03:02:08

问题


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).


回答1:


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.




回答2:


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

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



回答3:


Just set the orientation of the ItemsWrapGrid:

<GridView.ItemsPanel>
    <ItemsPanelTemplate>
        <ItemsWrapGrid Orientation="Horizontal"/>
    </ItemsPanelTemplate>
</GridView.ItemsPanel>


来源:https://stackoverflow.com/questions/14260632/order-items-horizontal-in-xaml-gridview-win8-metro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!