简体   繁体   English

我怎样才能使列表框*大小?

[英]How can i make listbox to be * sized?

One of the problems i am facing is listbox only takes so much as is needed to display it's items. 我面临的问题之一是列表框只需要显示其项目所需的大量时间。 How can i make listbox to occupy the full space that is available to itself? 如何使列表框占据其可用的全部空间?

Example:- If i place the listbox inside the grid it should occupy the full grid. 示例:-如果我将列表框放在网格内,则它应该占据整个网格。

The current problem is if i give stretch to listbox and set it's height and width to Auto it will still only occupy the space it needs for displaying its items. 当前的问题是,如果我将拉伸赋予列表框并将其高度和宽度设置为“自动”,它将仍然仅占据显示其项目所需的空间。

Thanks in advance :) 提前致谢 :)

The ListBox itself will stretch to fill a * sized cell in a Grid. ListBox本身将拉伸以填充Grid中大小为*的单元格。 The problem is that the content of the ListBox doesn't do this. 问题在于ListBox的内容无法执行此操作。

You can do something about this for the width of the content items in a vertically oriented ListBox:- 您可以为此在垂直方向的ListBox中对内容项的宽度进行处理:

<ListBox.ItemContainerStyle>
   <Setter Property="HorizontalContentAlignment" Value="Stretch" />
</ListBox.ItemContentStyle>

This will cause the items (if their template allows) to stretch the width of the ListBox. 这将导致项目(如果其模板允许)拉伸ListBox的宽度。

However for Horizontally oriented ListBox it would be tricker to get content to stretch to the height of the ListBox since the default ListBoxItem template does not bind the VerticalContentAlignment property. 但是,对于水平放置的ListBox,要使内容拉伸到ListBox的高度会比较麻烦,因为默认的ListBoxItem模板不会绑定VerticalContentAlignment属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM