Vertical Align in WPF TextBox

開発者 picture 開発者 · Dec 15, 2010 · Viewed 46.3k times · Source

I have 2 TextBoxes in my wpf app, one for user name and other for password, both have FontSize=20, but the text appears like this:

alt text

How can I fix this?

Xaml:

<TextBox Grid.Row="1" Grid.Column="1" Height="40" BorderThickness="1" BorderBrush="#FFD5D5D5" FontSize="36" Text="test" />
<PasswordBox Grid.Row="3" Grid.Column="1" Height="40" BorderThickness="1" BorderBrush="#FFD5D5D5" FontSize="36" Password="test" />

Answer

Tal Segal picture Tal Segal · Jul 7, 2013

To Center the text in a TextBox use the VerticalContentAlignment Property of the TextBox.

<TextBox Text="The text" Height="40" VerticalContentAlignment="Center" />