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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM