TextBox文本内容在整个TextBox处于拉伸模式时与中心对齐

时间:2017-10-24 13:41:59

标签: c# wpf textbox

嗨我有一个TextBox,我想填充我为它定义的网格。要做到这一点,我把它放在拉伸,所以它可以适合。问题是文本将被写在顶部而不是中心。如果我将对齐设置为居中,则TextBox将不再延伸。

<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="3" Grid.Column="0" Text="Wall Temperature [C]"/>
<TextBox HorizontalAlignment="Stretch"  VerticalAlignment="Center" Grid.Row="3" Grid.Column="1" Text="150.0"/>
<TextBlock HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Row="4" Grid.Column="0" Text="Wall Temperature [C]"/>
<TextBox HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" Grid.Row="4" Grid.Column="1" Text="150.5"/>

看起来像这样

enter image description here

1 个答案:

答案 0 :(得分:1)

如果您希望其中的文字垂直对齐,则需要修改ControlTemplate的{​​{1}}:

TextBox

enter image description here