Omu
Omu

Reputation: 71288

wpf layout question

<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

Upvotes: 0

Views: 225

Answers (2)

Thomas Levesque
Thomas Levesque

Reputation: 292715

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...

Upvotes: 5

Bubblewrap
Bubblewrap

Reputation: 7526

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).

Upvotes: 2

Related Questions