sarat
sarat

Reputation: 11110

How to layout controls and make it resizable

I would like to place the controls as listed below in WPF. Please given an example to do the same.

Layout

Upvotes: 0

Views: 48

Answers (1)

K Mehta
K Mehta

Reputation: 10533

<Grid x:Name="ContentRoot">
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="200"/>
    <ColumnDefinition Width="*"/>
    <ColumnDefinition Width="100"/>
    <ColumnDefinition Width="100"/>
  </Grid.ColumnDefinitions>

  <TextBlock Grid.Column="0" .../>
  <TextBox Grid.Column="1" .../>
  <Button Grid.Column="2" .../>
  <Button Grid.Column="3" .../>
</Grid>

Assuming that ContentRoot is placed directly in your Window, it'll inherit it's Width and Height from the Window. Then it'll assign 200px to the 0th column, and 100px each to the 2nd and 3rd columns. And any leftover space will be assigned to the 1st column.

Of course, you can change 200, 100, and 100 to whatever you want.

If needed, add MinWidth="<value>" (replace <value> with a number) in the 1st ColumnDefnition to specify a minimum width that column must have.

Upvotes: 2

Related Questions