【WPF】設置ListBox容器Item的流式布局


需求:像下圖那樣顯示把一組內容裝入ListBox中顯示。要求用WrapPanel橫向布局,順序如圖中的數字。

問題:ListBox默認的布局是從上往下單列的,所以需要設置布局。

<ListBox x:Name="HousePlansLB">
    <ListBox.Template>
        <ControlTemplate TargetType="ListBox">
            <WrapPanel Width="600" Orientation="Horizontal" IsItemsHost="True"/>
        </ControlTemplate>
    </ListBox.Template>

    <TextBox Text="測試1" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="測試2" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="測試3" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="測試4" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="測試5" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="測試6" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
    <TextBox Text="測試7" Width="140" Height="90" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</ListBox>

實際使用中,還要給ListBox設置它的ItemsSource綁定到ViewModel中的某個列表,不會是向上面那樣直接手打一串的TextBox的。

重要的參考:

http://www.cnblogs.com/qishichang/archive/2010/09/30/1839040.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM