原文:#400 – 使用ItemsPanel 属性将WrapPanel 作为ListBox的显示面板(Using a WrapPanel as the Items Panel for a ListBox)

ListBoxItemsPanel 属性可以指定定义显示各子项的面板的模板。你可以通过定义自己的模板重写ListBox 常见的垂直堆叠式布局。

如果你设置了ItemsPanel 模板为WrapPanelListBox 将会有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/



最新文章

  1. zepto.js学习
  2. 关于synchronized 影响可见性的问题
  3. openlayers优化项
  4. error: src refspec master does not match any. 错误处理办法
  5. Unit03 - 对象内存管理 、 继承的意义(上)
  6. editplus快捷键大全之editplus文件快捷键
  7. Android开发之ADT导入Support Library
  8. bzoj1054
  9. spring注解方式 idea报could not autowire,eclipse却没有问题
  10. Hadoop集群运行JNI程序
  11. C++算术运算符与算术表达式
  12. JDK源码之AQS源码剖析
  13. Debian Security Advisory DSA-4419-1 twig security update
  14. SpringMVC概述
  15. Multi-Projector Based Display Code ---- ModelViewer
  16. P1967 货车运输
  17. Javascript 实现[网红] 时间轮盘
  18. IntelliJ IDEA maven springmvc+shiro简单项目
  19. scanf printf gets() puts(),cin cout
  20. 【BZOJ4099】Trapped in the Haybales Gold STL

热门文章

  1. 读写appSettings配置节方法
  2. [SQLServer] 内存占用查看
  3. C语言const与#define
  4. ASP.NET MVC下Bundle的使用
  5. Oracle诊断工具 - ORA-4030 Troubleshooting Tool
  6. sonarQube常见问题及分析
  7. asp.net core中DockerFile文件中的COPY
  8. input file实现多选,限制文件上传类型,图片上传前预览功能
  9. 阿里八八Alapa事后诸葛亮
  10. SGU---101 无向图的欧拉回路