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)
The way to stretch it to the same size as the parent container is to use the attribute:
That will make the Textbox element stretch horizontally and fill all the parent space horizontally (actually it depends on the parent panel you’re using but should work for most cases).
Percentages can only be used with grid cell values so another option is to create a grid and put your textbox in one of the cells with the appropriate percentage.