WPF listbox实现多列显示数据

一.每行显示固定列数

<ListBox ItemsSource="{Binding DataList}" Style="{DynamicResource ListBoxStyle}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <UniformGrid Columns="3"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            ...
                        </DataTemplate>
                    </ListBox.ItemTemplate>
</ListBox>

二.每行显示列数随宽度变化

<ListBox ItemsSource="{Binding DataList}" Style="{DynamicResource ListBoxStyle}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>          
                            <WrapPanel IsItemsHost="True"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            ...
                        </DataTemplate>
                    </ListBox.ItemTemplate>
</ListBox>

 

posted @ 2016-01-17 14:04  骑猪上学  阅读(7072)  评论(2编辑  收藏  举报