在没有 WPF 网格的情况下对齐列

发布于 2024-08-07 03:40:22 字数 809 浏览 2 评论 0原文

我正在寻找一种设计多列布局的好方法,该方法根据可用空间重新排列列中的控件。我有一个显示信息的标签和字段列表,有时它们包含的视图需要又高又瘦,有时又短又宽。

一个简单的解决方案是使用 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>

我希望标签和值全部水平排列成列,而不指定静态宽度。现在,LabelTextBlock 只是根据其内容调整大小。

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 Labels and TextBlocks are just sized based on their content.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

梦旅人picnic 2024-08-14 03:40:22

您是否尝试将 WrapPanel 添加为 ListBox 中的 ItemsContainer?

<ListBox>
  <ListBox.ItemsContainer>
    <WrapPanel />
  </ListBox.ItemsContainer>
</ListBox>

Did you try to add WrapPanel as an ItemsContainer in ListBox?

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