views:

92

answers:

1

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.

+1  A: 

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

<ListBox>
  <ListBox.ItemsContainer>
    <WrapPanel />
  </ListBox.ItemsContainer>
</ListBox>
ArsenMkrt
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.
emddudley