WPF中的ListBox完成按塊顯示元素的辦法。本站提示廣大學習愛好者:(WPF中的ListBox完成按塊顯示元素的辦法)文章只能為提供參考,不一定能成為您想要的結果。以下是WPF中的ListBox完成按塊顯示元素的辦法正文
本文實例講述了WPF中的ListBox完成按塊顯示元素的辦法。分享給年夜家供年夜家參考,詳細以下:
留意:須要設置ListBox的屬性 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
症結代碼,WPF中有內置的WrapPanel控件,在ListBox.ItemsPanel中應用可讓元素按塊顯示
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox Height="304" HorizontalAlignment="Left" Margin="14,143,0,0" Name="lstTables" VerticalAlignment="Top" Width="615" ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="20,20,20,20">
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Image Source="Images/table.png" Grid.Row="0" Height="42" Width="42" HorizontalAlignment="Center">
<Image.Effect>
<DropShadowEffect/>
</Image.Effect>
</Image>
<TextBlock Text="{Binding FTableName,Mode=TwoWay}" Grid.Row="1" HorizontalAlignment="Center" Margin="5,5,5,5" />
<CheckBox IsChecked="{Binding FSelected,Mode=TwoWay,Converter={StaticResource SelCTS}}" Grid.Row="2" HorizontalAlignment="Center">
<CheckBox.Effect>
<DropShadowEffect/>
</CheckBox.Effect>
</CheckBox>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
願望本文所述對年夜家C#法式設計有所贊助。