0
<Window ... >
    <StackPanel>
        <Button>b1</Button>
        <Button>b2</Button>
    </StackPanel>
</Window>

how to make this look like this:

<Window ...>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>

        <Button>b1</Button>
        <Button Grid.Row="1">b2</Button>
    </Grid>
</Window>

without using a grid

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
Omu
  • 69,856
  • 92
  • 277
  • 407
  • 2
    A stack panel doesn't behave like a grid because its not meant to be a grid. Its meant to be a stack panel. If it was meant to act like a grid it would be a grid. Sorta like how buttons behave differently than text boxes and birds don't tunnel under my lawn. –  Aug 14 '09 at 13:02
  • What do you mean make it look like that? In what way? – Carlo Aug 14 '09 at 15:49
  • i meant for the stackpanel to occupy the whole window, jut like the grid – Omu Aug 17 '09 at 05:57

2 Answers2

5

You could try that :

<Window ... >
    <UniformGrid Rows="2" Columns="1">
        <Button>b1</Button>
        <Button>b2</Button>
    </UniformGrid>
</Window>

Not as flexible as a full blown Grid, but simpler to use...

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
2

Short answer: You can't.

Long answer: Write a custom Panel and override ArrangeOverride and MeasureOverride to simulate Grid behaviour.

StackPanel arranges each of its child elements to use minimal height (or minimal width if Orientation == Horizontal). StackPanel offers no properties to alter this behaviour. Grid on the other hand, unless indicated otherwise, will divide all available space evenly across each child (or rather row/column).

Bubblewrap
  • 7,266
  • 1
  • 35
  • 33