How to fit textbox width with a set of columns in a grid?

Guilherme Campos picture Guilherme Campos · Feb 28, 2012 · Viewed 7.1k times · Source

Supose I have a grid with 4 columns and want to put a textbox in the second column and span it to the last column. How could I fit the textbox width to be as wide as the 3 last columns?

I have tried something with Borders, but it didn't work.

<Grid>
      <Grid.ColumnDefinitions>
           <ColumnDefinition Width="Auto" />
           <ColumnDefinition Width="Auto" />
           <ColumnDefinition Width="Auto" />
           <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>

      <TextBox Grid.Column="1" Grid.ColumnSpan="3" />
</Grid>

Answer

Dipesh Bhatt picture Dipesh Bhatt · Feb 28, 2012

Give TextBox some width or make ColumnDefinition width as * instead of Auto. It is spanning till the last column but just you are not able to see it as the width is Auto.