我在我的專案中創建了一個從檔案夾中獲取影像的系統,并將其放在 ItemsSource 之類的串列框中,我想像這樣安排它:

1 2 3
4 5 6
7 8 9
如果我像大視窗一樣調整視窗大小,這會發生什么:
1 2 3 4
5 6 7 8
9 .. ..
但我在安排清單時遇到了問題。以及如何從 ItemsSource 獲取文本 selectedItem 如何?這里的代碼:
<Window.Resources>
<DataTemplate x:Key="TileTemplate">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="55"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="Images/folder.png" Margin="10" Height="40" Width="35"/>
<TextBlock Grid.Row="1" Margin="3,0,0,5" TextAlignment="Center" Text="{Binding Names}" Width="70"/>
</Grid>
</DataTemplate>
<ItemsPanelTemplate x:Key="TilePanel">
<WrapPanel/>
</ItemsPanelTemplate>
<Style TargetType="local:LayoutListBox">
<Style.Triggers>
<Trigger Property="ViewLayout" Value="Tile">
<Setter Property="ItemsPanel" Value="{StaticResource TilePanel}"/>
<Setter Property="ItemTemplate" Value="{StaticResource TileTemplate}"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
uj5u.com熱心網友回復:
你可以這樣做:
<ListBox ItemsSource="{Binding YourList}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
然后,即使您放大視窗,每列中也會留下3 個專案
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/440632.html
