#332 – HorizontalContentAlignment and VerticalContentAlignment Are Sometimes Not Relevant
June 30, 2011 Leave a comment
The HorizontalContentAlignment and VerticalContentAlignment properties, used to align a control’s content within the interior of the control, only make sense if the control is not automatically sizing to fit its content.
In the example below, all three buttons have their HorizontalContentAlignment property set to Right. The first button has the default value for its HorizontalAlignment property (Stretch), so you can see the content of the button aligned to the right. The other two buttons are not stretched, so their width is set to fit their content. For these buttons, setting the HorizontalContentAlignment property doesn’t have any visible effect.
<StackPanel> <Button Content="HorizontalAlignment=Stretch (Default)" HorizontalContentAlignment="Right"/> <Button Content="HorizontalAlignment=Left" HorizontalAlignment="Left" HorizontalContentAlignment="Right"/> <Button Content="HorizontalAlignment=Right" HorizontalAlignment="Right" HorizontalContentAlignment="Right"/> </StackPanel>