alansiqueira27
alansiqueira27

Reputation: 8534

How to center a label text in WPF?

How to center a label text in WPF?


Label HorizontalAlignment="Center" Content="What?" FontSize="25" FontWeight="Bold" Canvas.Top="5"

Upvotes: 126

Views: 180322

Answers (4)

Kombinator
Kombinator

Reputation: 105

You have to use HorizontalContentAlignment="Center" and! Width="Auto".

Upvotes: 4

Newred
Newred

Reputation: 729

Sample:

Label label = new Label();
label.HorizontalContentAlignment = HorizontalAlignment.Center;

Upvotes: 0

Akshay J
Akshay J

Reputation: 5468

The Control class has HorizontalContentAlignment and VerticalContentAlignment properties. These properties determine how a control’s content fills the space within the control.
Set HorizontalContentAlignment and VerticalContentAlignment to Center.

Upvotes: 8

biju
biju

Reputation: 18030

use the HorizontalContentAlignment property.

Sample

<Label HorizontalContentAlignment="Center"/>

Upvotes: 244

Related Questions