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