wpf 文本框 - 文本居中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3485727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Textbox - text centering
提问by noname
Is there any simple way to center a text in textbox? I was looking for some built-in functions, but I found nothing.
有没有什么简单的方法可以让文本框中的文本居中?我一直在寻找一些内置函数,但一无所获。
回答by Thomas Levesque
Set the TextAlignment
property to Center
:
将TextAlignment
属性设置为Center
:
<TextBox Width="200"
Text="Hello world !"
TextAlignment="Center"/>
回答by Tar?k ?zgün Güner
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
回答by Ghotekar Rahul
You can reach the text within a WPF-TextBox with the combination VerticalAlignment and VerticalContentAlignment. You set the content to center and the total height with Stretch to the size of the comprehensive element like a grid row
您可以使用 VerticalAlignment 和 VerticalContentAlignment 的组合来访问 WPF-TextBox 中的文本。您将内容设置为居中,使用 Stretch 将总高度设置为网格行等综合元素的大小
<TextBox VerticalAlignment="Stretch" VerticalContentAlignment="Center">
Test
</TextBox>
回答by Sonhja
<TextBox Width="200" Text="Hello world !" VerticalAlignment="Center"/>
回答by Othman Dahbi-Skali
it's too late but this may be helpful for someone
为时已晚,但这可能对某人有所帮助
Try adding this two peoperties to your control
尝试将这两个peoperties添加到您的控件中
VerticalAlignment="Stretch"
VerticalContentAlignment="Center"
回答by Naveen S
<TextBox VerticalAlignment="Center" Padding="5" >
VerticalAlignment = "Center" and padding You can reach the text within a WPF-TextBox with the combination VerticalAlignment and Padding. Like VerticalAlignment = "Center" Padding = "5" Padding causes the text field to become larger and adapt to the surrounding element.
VerticalAlignment = "Center" 和 padding 您可以使用 VerticalAlignment 和 Padding 的组合来访问 WPF-TextBox 中的文本。像 VerticalAlignment = "Center" Padding = "5" Padding 使文本字段变大并适应周围元素。
回答by justme
VerticalContentAlignment sets the Alignment for the Text in a Textbox
VerticalContentAlignment 设置文本框中文本的对齐方式