#400 – 使用ItemsPanel 属性将WrapPanel 作为ListBox的显示面板(Using a WrapPanel as the Items Panel for a ListBox)
2024-10-18 15:31:41
原文:#400 – 使用ItemsPanel 属性将WrapPanel 作为ListBox的显示面板(Using a WrapPanel as the Items Panel for a ListBox)
ListBox 的ItemsPanel 属性可以指定定义显示各子项的面板的模板。你可以通过定义自己的模板重写ListBox 常见的垂直堆叠式布局。
如果你设置了ItemsPanel 模板为WrapPanel,ListBox 将会有WrapPanel的特性。
在下面的例子中,我们将上一篇中的ListBox 稍作修改。指定ItemsPanel 包含一个WrapPanel。
<Grid>
<ListBox ItemsSource="{Binding MovieList}" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Image Source="{Binding Image}" Stretch="None"/>
<Label Content="{Binding TitleWithYear}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
可以看到,将ItemsPanel 设置为WrapPanel后,改变窗口的大小,ListBox显示会自动根据窗口大小换行。
原文地址:https://wpf.2000things.com/2011/10/04/400-using-a-wrappanel-as-the-items-panel-for-a-listbox/
最新文章
- zepto.js学习
- 关于synchronized 影响可见性的问题
- openlayers优化项
- error: src refspec master does not match any. 错误处理办法
- Unit03 - 对象内存管理 、 继承的意义(上)
- editplus快捷键大全之editplus文件快捷键
- Android开发之ADT导入Support Library
- bzoj1054
- spring注解方式 idea报could not autowire,eclipse却没有问题
- Hadoop集群运行JNI程序
- C++算术运算符与算术表达式
- JDK源码之AQS源码剖析
- Debian Security Advisory DSA-4419-1 twig security update
- SpringMVC概述
- Multi-Projector Based Display Code ---- ModelViewer
- P1967 货车运输
- Javascript 实现[网红] 时间轮盘
- IntelliJ IDEA maven springmvc+shiro简单项目
- scanf printf gets() puts(),cin cout
- 【BZOJ4099】Trapped in the Haybales Gold STL