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 @ 2019-01-10 17:34  willamyao  阅读(4203)  评论(0编辑  收藏  举报