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>
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.
As Dipesh Bhatt has rightly put in his answer that solution to your problem is to put * or something specific as width for columns.
What happens in your example is auto width for column says "take as much is required" hence it takes very little width, as empty textbox will require very very small width, which is hardly visible.
A * in width for column says "acquire whatever space is available" this will increase width of column hence it will give more space to textbox.
This means you have already achieved what you wanted but its hardly visible due to minimal width of columns.
Right now the last 3 columns are fitting the text box as the width is auto.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="1" Grid.ColumnSpan="3" />
</Grid>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With