在没有 WPF 网格的情况下对齐列
我正在寻找一种设计多列布局的好方法,该方法根据可用空间重新排列列中的控件。我有一个显示信息的标签和字段列表,有时它们包含的视图需要又高又瘦,有时又短又宽。
一个简单的解决方案是使用 WrapPanel:
<WrapPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label>Some label:</Label>
<TextBlock>Some value</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label>Some other label:</Label>
<TextBlock>Some bigger value</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label>A:</Label>
<TextBlock>B</TextBlock>
</StackPanel>
</WrapPanel>
我希望标签和值全部水平排列成列,而不指定静态宽度。现在,Label
和 TextBlock
只是根据其内容调整大小。
I am looking for a good way to design a multi-column layout which reflows the controls in the columns according to the space available. I have a list of labels and fields which display information, and sometimes the view they are contained in needs to be tall and skinny, other times short and wide.
A simple solution is to use a WrapPanel
:
<WrapPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Label>Some label:</Label>
<TextBlock>Some value</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label>Some other label:</Label>
<TextBlock>Some bigger value</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Label>A:</Label>
<TextBlock>B</TextBlock>
</StackPanel>
</WrapPanel>
I want the labels and values all to line up horizontally into columns, without specifying a static width. Right now the Label
s and TextBlock
s are just sized based on their content.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试将 WrapPanel 添加为 ListBox 中的 ItemsContainer?
Did you try to add WrapPanel as an ItemsContainer in ListBox?