使列表框填充父容器的宽度

发布于 2024-10-14 22:39:25 字数 362 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

醉酒的小男人 2024-10-21 22:39:25

我敢打赌,您的 ListBox 正在填充其父容器的宽度,但列表框中的 ListBoxItems 不会水平拉伸。尝试添加以下样式:

 <ListBox.ItemContainerStyle> 
     <Style TargetType="ListBoxItem"> 
         <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> 
     </Style> 
 </ListBox.ItemContainerStyle> 

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.ItemContainerStyle> 
     <Style TargetType="ListBoxItem"> 
         <Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter> 
     </Style> 
 </ListBox.ItemContainerStyle> 
夕嗳→ 2024-10-21 22:39:25

默认情况下,ListBox 应填充 DockPanel。

我刚刚尝试过:

<DockPanel>
  <ListBox Background="Red" />
</DockPanel>

效果非常好。如果没有您的代码片段,我们将很难看出问题所在。

A ListBox should fill the DockPanel by defualt.

I just tried:

<DockPanel>
  <ListBox Background="Red" />
</DockPanel>

and it worked perfectly. Will be hard for us to see what the problem is without a snippet of your code.

疑心病 2024-10-21 22:39:25

我必须从列表框中删除所有“对齐”属性才能使其正常工作。确保从列表框定义中删除 Horizo​​ntalAlignment 和 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文