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"


use the HorizontalContentAlignment property.


<Label HorizontalContentAlignment="Center"/>

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.

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


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

Need Your Help

How do I connect to an .mdf (Microsoft SQL Server Database File) in a simple web project?

c# database visual-studio-2008

Specifically, in VS 2008, I want to connect to a data source that you can have by right-clicking on the automatically-generated App_Data folder (an .mdf "database"). Seems easy, and it is once you ...

Nodejs library without nodejs

javascript node.js

How can I integrate a nodejs library into my non nodejs project?