30

I want the content of a wpf button to be left aligned I tried the following but the text is still centered inside the button.

    <Button >
        <StackPanel HorizontalAlignment="Stretch">
            <TextBlock HorizontalAlignment="Left" Text="Save"/>
        </StackPanel>
    </Button>

What do i do?

H.B.
  • 166,899
  • 29
  • 327
  • 400
Jose
  • 10,891
  • 19
  • 67
  • 89

3 Answers3

71

Found it, it's HorizontalContentAlignment.

:)

H.B.
  • 166,899
  • 29
  • 327
  • 400
Jose
  • 10,891
  • 19
  • 67
  • 89
17

You don't need the StackPanel or the TextBlock. All you need is

<Button HorizontalContentAlignment="Left" Content="Save" />
Bryan Anderson
  • 15,969
  • 8
  • 68
  • 83
5

You can align in two way, Horizontal and Vertical

<Button Content="Export" VerticalContentAlignment="Bottom" name="MyBtn1"  />

or

<Button Content="Export" HorizontalContentAlignment="Center" name="MyBtn2"  />

See the follow image to view the possibilities settings:

enter image description here

enter image description here

daniele3004
  • 13,072
  • 12
  • 67
  • 75