Say I want a TextBlock
to have its Width
equal to it's Parent container's Width
(ie, stretch from side to side) or a percentage of it's Parent Container Width
, how can I accomplish this in XAML
without specifying absolute values?
I want to do this so that if the Parent Container container is later on expanded (its' Width
increased), its' Child Elements will also be expanded automatically. (basically, like in HTML and CSS)
You can put the textboxes inside a grid to do percentage values on the rows or columns of the grid and let the textboxes auto-fill to their parent cells (as they will by default). Example:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="3*" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" />
<TextBox Grid.Column="1" />
</Grid>
This will make #1 2/5 of the width, and #2 3/5.