我试图使用VerticalContentAlignment属性垂直居中TextBox的内容,但它似乎根本没有任何效果.文字保持在顶部.谁能告诉我怎么做?
这是我的代码:
<TextBox Grid.Column="1" Grid.Row="0" Width="200" Height="28" VerticalAlignment="Center" VerticalContentAlignment="Center" />
解决方法
可以使TextBox中心垂直显示文本.但是,这确实需要您重新应用其ControlTemplate.
去做这个:
>将Style和ControlTemplate从TextBox Styles and Templates page on MSDN复制到合适的< UserControl.Resources>元件. (此ControlTemplate实际上是用于验证工具提示;我们将更改的ControlTemplate在Style中.)
>在TextBox的Style中查找ScrollViewer元素,并为其添加VerticalAlignment =“Center”属性.
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
到ScrollViewer.这应该允许您使用VerticalContentAlignment属性设置TextBoxes内容的垂直对齐方式.