开发者

How to center a label text in WPF?

How to center a label text in WPF?


Lab开发者_StackOverflow中文版el HorizontalAlignment="Center" Content="What?" FontSize="25" FontWeight="Bold" Canvas.Top="5"


use the HorizontalContentAlignment property.

Sample

<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".


Sample:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜