根据列表框尺寸调整列表框内容的大小
我正在尝试根据列表框本身调整列表框内容的大小。这是在 WPF 中完成的。
关于这如何可能的任何想法?
I am attempting to resize the contents of my listbox according to the listbox itself. This is being done in WPF.
Any ideas on how this might be possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为当您说“调整大小”时,您的意思是您想要在两个方向上拉伸项目。要采用默认的 ListBox 并水平拉伸项目,您需要做的就是:
默认为 Left,因此所有 ListBoxItems 最终都会被推到左侧,并根据其内容单独调整大小。
垂直拉伸需要摆脱用于对项目进行布局的 StackPanel,因为它没有在 Orientation 方向上调整其子项大小的概念。最简单的使用是 UniformGrid,但您可能需要更自定义的东西,具体取决于您希望项目相对于彼此的大小如何。您还需要对 VerticalContentAlignment 设置(默认为居中)执行相同的操作。所以这是一个可以双向拉伸项目的方法:
I assume when you say "resize" you mean that you want to stretch the items in both directions. To take a default ListBox and stretch the items horizontally all you need is:
The default is Left so all the ListBoxItems end up pushed to the left and sized individually based on their content.
Vertical stretching requires getting rid of the StackPanel used to do layout for the items because it has no concept of resizing its children in the direction of Orientation. The simplest thing to use is a UniformGrid but you might want something more custom depending on how you want the items to size relative to each other. You'll also need to do the same thing with the VerticalContentAlignment setting (Center by default). So here's one that will stretch items both ways: