0

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.

sourcenouveau
  • 29,356
  • 35
  • 146
  • 243

1 Answers1

1

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

<ListBox>
  <ListBox.ItemsContainer>
    <WrapPanel />
  </ListBox.ItemsContainer>
</ListBox>
Arsen Mkrtchyan
  • 49,896
  • 32
  • 148
  • 184
  • ListBox does not have an ItemsContainer property. Were you referring to ItemsPanel? If so, could you elaborate on your suggestion? It seems like an interesting approach. – sourcenouveau Oct 09 '09 at 16:44