What is the difference between:
HorizontalAlignment=\"Stretch\"
HorizontalContentAlignment=\"Stretch\"
in a
HorizontalAlignment
and VerticalAlignment
determine the alignment of the control itself with respect to its parent control.
HorizontalContentAlignment
and VerticalContentAlignment
determine the controls content alignment with respect to the control.
For example consider a common Button control
Here you somehow have to specify how this control is aligned within it's parent control. A suitable parent control could be a StackPanel, a Grid, a WrapPanel etc.
For both Horizontal
- and VerticalAlignment
you can chose between the options Left
, Right
, Center
and Stretch
. The first three options respect the buttons width and height whereas the last option tries to stretch the button into the direction specified ignoring the set width or height:
The code
for example would place the Button inside the StackPanel and align it inside at the left.
HorizontalContentAlignment
and VerticalContentAlignment
aligns the content of the control. The content is special UIControl that is build into the control which you can simply exploit by taking a look into the ControlTemplate of a ContentControl. Note that we are talking especially about ContenControls which are acting as a container that is capable of taking exactly one object to 'carry' inside and display - its content.
So HorizontalContentAlignment
and VerticalContentAlignment
are determining the alignment of this content with respect to its container. In the case of a initially created Button the buttons content is its caption and with the two properties in question you are aligning this caption inside the Buttons borders which is again either one of these: Left, Right, Center, Stretch.