WPF中的ListBox实现按块显示元素的方法
作者:永远爱好写程序 时间:2021-06-11 03:39:03
本文实例讲述了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#程序设计有所帮助。
标签:WPF,ListBox
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java获取环境变量(System.getenv)的方法
2021-10-06 03:23:47
![](https://img.aspxhome.com/file/2023/4/104194_0s.png)
java实现动态代理示例分享
2023-04-28 15:54:49
![](https://img.aspxhome.com/file/2023/6/80316_0s.jpg)
Struts和servlet不能共存问题解决方法
2022-09-20 07:26:59
kettle中使用js调用java类的方法
2022-05-09 00:06:31
Java Callable接口实现细节详解
2023-11-10 05:34:26
![](https://img.aspxhome.com/file/2023/5/58995_0s.png)
Unity 按钮事件封装操作(EventTriggerListener)
2022-07-08 10:07:08
![](https://img.aspxhome.com/file/2023/7/113687_0s.jpg)
使用Java将一个List运用递归转成树形结构案例
2021-10-14 15:18:30
![](https://img.aspxhome.com/file/2023/5/77485_0s.jpg)
Hadoop之Mapreduce序列化
2022-05-08 10:18:19
![](https://img.aspxhome.com/file/2023/3/82303_0s.png)
Java PreparedStatement用法详解
2023-08-08 20:20:51
![](https://img.aspxhome.com/file/2023/1/58061_0s.png)
java使用Jdom实现xml文件写入操作实例
2022-09-30 02:38:23
Spring事务失效的场景梳理总结
2023-02-23 16:23:24
java同步之如何写一个锁Lock
2023-04-23 08:10:54
![](https://img.aspxhome.com/file/2023/3/63843_0s.png)
springboot中通过lua脚本来获取序列号的方法
2023-05-05 04:25:44
![](https://img.aspxhome.com/file/2023/9/97969_0s.png)
解决IDEA2020 创建maven项目没有src/main/java目录和webapp目录问题
2022-05-29 07:57:18
![](https://img.aspxhome.com/file/2023/0/81260_0s.png)
Java中Request请求转发详解
2021-05-25 20:53:42
![](https://img.aspxhome.com/file/2023/8/61538_0s.png)
Java多线程之线程通信生产者消费者模式及等待唤醒机制代码详解
2022-10-31 11:17:22
spring boot 使用profile来分区配置的操作
2022-11-27 22:55:15
![](https://img.aspxhome.com/file/2023/5/64205_0s.png)
c#项目将dll打包到exe中的步骤
2021-06-21 14:44:25
浅析C# Dynamic关键字
2022-11-24 03:01:42
Java的运算符和程序逻辑控制你了解吗
2023-01-19 10:01:59