当 WPF 文本框是多行时,如何显示文本对齐到顶部

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14942314/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 07:36:29  来源:igfitidea点击:

How to display text alignment to top, when WPF text box is a multiline

wpfwpf-controls

提问by user1794624

When i use multiline text box the text/content of text box should align to top, and if it is a single line text box then it text alignment should be default one(Center), i need to set this in text box style, so when ever there is a multiline text box my style will automatically adjust the content accordingly.

当我使用多行文本框时,文本框的文本/内容应该对齐到顶部,如果它是单行文本框,那么它的文本对齐应该是默认的(居中),我需要在文本框样式中设置它,所以当有一个多行文本框时,我的样式会相应地自动调整内容。

回答by Farzad J

you only need to set VerticalContentAlignment="Top"in your textbox like:

你只需要VerticalContentAlignment="Top"在你的文本框中设置,如:

<TextBox     
    TextWrapping="Wrap" 
    AcceptsReturn="True" 
    Text="sample ... "
    VerticalContentAlignment="Top"                                
/>