none
WPF Label text alignment RRS feed

  • Question

  • Hi,

    I've dropped a 200px label on to my 800px Window with the text "TEST".

    However, when I set the alignment to left/right this sets the alignment of the label not the text inside the label.

    <Label x:Name="lblExample" Content="TEST" HorizontalAlignment="Right" Margin="90,100,0,0" VerticalAlignment="Top" Width="200" Foreground="White" FontSize="16"/>

    How do I set the alignment of the text inside a label?

    Thanks

    Sunday, January 11, 2015 8:50 PM

Answers

  • Hi BudBrain,

    >>when I set the alignment to left/right this sets the alignment of the label not the text inside the label.

    You need to use HorizontalContentAlignment property to set the horizontal alignment of the control's content:

    <Label x:Name="lblExample" Content="TEST" HorizontalContentAlignment="Left" HorizontalAlignment="Right" VerticalAlignment="Top" Width="180" Foreground="Black" FontSize="16"/>

    HorizontalAlignment property is to set the horizontal alignment characteristics applied to this element when it is composed within a parent element: http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.horizontalalignment(v=vs.110).aspx


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 12, 2015 12:15 PM
    Moderator