0

I already set my ListView on C#, the problem is XAML. My current code Works like this :

<ListView x:Name="List" ItemsSource="{Binding}" SelectionChanged="List_SelectionChanged">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid Margin="11" Width="460">
                <StackPanel Orientation="Vertical" >
                    <Image Width="100" Height="100"
                       Source="{Binding Way}"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

But I want to do something like this:

enter image description here

4

1 回答 1

2

对于您的场景,我认为您可以使用GridView而不是ListView. GridView在行和列中显示数据集合,而 ListView 显示垂直堆叠的集合。

默认情况下,GridView使用ItemsWrapGridas its ItemsPanel,在使用 时ItemsWrapGrid,我们可以使用 property 设置ItemsWrapGrid.MaximumRowsOrColumns属性ItemsWrapGrid.Orientation以将最大列限制为2

例如:

<GridView ItemsSource="{Binding}" SelectionChanged="GridView_SelectionChanged">
    <GridView.ItemTemplate>
        <DataTemplate>
            <Grid Width="460" Margin="11">
                <StackPanel Orientation="Vertical">
                    <Image Width="100" Height="100" Source="{Binding Way}" />
                </StackPanel>
            </Grid>
        </DataTemplate>
    </GridView.ItemTemplate>
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid MaximumRowsOrColumns="2" Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</GridView>
于 2016-03-10T09:30:13.123 回答