使列表框填充父容器的宽度
我有一个 DockPanel,其中有一个列表框。停靠面板成功填充了整个窗口的宽度。现在,我希望列表框填充整个 DockPanel 的宽度。
我尝试了很多事情...包括在其周围包裹网格并将列设置为 * 的宽度,将列表框的水平对齐设置为拉伸,等等。我似乎无法让这个愚蠢的列表框填充宽度。
该列表框确实有一个 ItemTemplate,但其中的所有内容都具有自动宽度拉伸的水平对齐方式。每当您将 ItemTemplate 的宽度设置为静态值时,列表框都会相应地调整大小。我只是无法让它填补父母的空缺。
谢谢。
编辑:
谢谢大家让我意识到这是我的错......事实证明这是风格标签中的一个错误。
我现在将尝试删除这个问题。
I have a DockPanel with a listbox in it. The dockpanel successfully fills the width of the entire window. Now, i want the Listbox to fill the width of the entire DockPanel.
I have tried many things... including wrapping a grid around it and setting the column to width of *, setting the horizontalalignment of the listbox to stretch, and numerous others. I cannot seem to get this silly listbox to fill the width.
This listbox DOES have an ItemTemplate, but everything inside it has a horizontal alignment of stretch with auto width. Whenever you set the ItemTemplate's width to something static, the listbox does resize appropriately. I just cannot get it to fill the parent.
Thanks.
EDIT:
Thanks guys for making me realize it's my fault... Turns out it was a goof in the style Tag.
I will attempt to remove this question now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我敢打赌,您的 ListBox 正在填充其父容器的宽度,但列表框中的 ListBoxItems 不会水平拉伸。尝试添加以下样式:
I would bet that your ListBox is filling the width of its parent container, but the ListBoxItems within your list box are not stretching horizontally. Try adding the following style:
默认情况下,ListBox 应填充 DockPanel。
我刚刚尝试过:
效果非常好。如果没有您的代码片段,我们将很难看出问题所在。
A ListBox should fill the DockPanel by defualt.
I just tried:
and it worked perfectly. Will be hard for us to see what the problem is without a snippet of your code.
您还可以使用
DockPanel.LastChildFill
属性:http://msdn.microsoft.com/en-us/library/system.windows.controls.dockpanel.lastchildfill.aspx
You can also use
DockPanel.LastChildFill
property:http://msdn.microsoft.com/en-us/library/system.windows.controls.dockpanel.lastchildfill.aspx
我必须从列表框中删除所有“对齐”属性才能使其正常工作。确保从列表框定义中删除 HorizontalAlignment 和 VerticalAlignment 分配。一旦我做到了这一点并将其包装在 DockPanel 中,正如上面所建议的,我就能够让它工作。
I had to remove all 'alignment' properties from the listbox to get this to work. Be sure that the HorizontalAlignment and VerticalAlignment assignments are removed from the listbox definition. Once I did this AND wrapped it in a DockPanel, as suggested above, I was able to get it to work.