WPF文本框中的垂直对齐 [英] Vertical Align in WPF TextBox
本文介绍了WPF文本框中的垂直对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的wpf应用程序中有2个TextBox
es,一个为用户名,另一个为密码,都带有FontSize=20
,但是文本显示如下:
I have 2 TextBox
es in my wpf app, one for user name and other for password, both have FontSize=20
, but the text appears like 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" />
推荐答案
调整这些控件的Padding
属性,例如Padding="0"
:
Adjust the Padding
properties of these controls, e.g. Padding="0"
:
<TextBox Grid.Row="1" Grid.Column="1" Height="40" BorderThickness="1" BorderBrush="#FFD5D5D5" FontSize="36" Text="test" Padding="0" />
<PasswordBox Grid.Row="3" Grid.Column="1" Height="40" BorderThickness="1" BorderBrush="#FFD5D5D5" FontSize="36" Password="test" Padding="0" />
或者,不要设置Height
属性,而是让控件根据其内容的高度自动调整大小:
Or, don't set the Height
properties, and instead let the controls size themselves automatically based on the height of their content:
<TextBox Grid.Row="1" Grid.Column="1" BorderThickness="1" BorderBrush="#FFD5D5D5" FontSize="36" Text="test" />
<PasswordBox Grid.Row="3" Grid.Column="1" BorderThickness="1" BorderBrush="#FFD5D5D5" FontSize="36" Password="test" />
这篇关于WPF文本框中的垂直对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文