WPF ListBox 实现多行多列定制内容显示

效果如图

关键代码

<ListBox Name="imageListBox" ItemsSource="{Binding }"
            Width="{Binding ElementName=listBoxShowImages,Path=Width,Mode=OneWay}" Loaded="imageListBox_Loaded">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="6"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
    <!--定制样式-->
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                <TextBlock Margin="3" Text="{Binding Name}" Width="100"/>
                <Image Margin="3" Source="{Binding Path}" Width="100" Height="100"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

单行Item个数设置

<UniformGrid Columns="6"/>

示例代码

ListBoxShowImages

posted @ 2020-12-12 11:24  Lulus  阅读(4051)  评论(2编辑  收藏  举报