需求:像下圖那樣顯示把一組內容裝入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