带有单行 WPF 的 TextBox

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

TextBox with single line WPF

wpf

提问by Shwed_Berlin

I'm using WPF.
I try to create single line TextBox not multi line.
What i'm trying is

我正在使用 WPF。
我尝试创建单行 TextBox 而不是多行。
我正在尝试的是

<StackPanel Orientation="Horizontal">
     <TextBox Margin="5" VerticalAlignment="Center" Text="Single line" />
</StackPanel>


But when i tried to enter a text, the TextBox is multiline and not single line
How can i fix it?
Thanks.


但是当我尝试输入文本时,TextBox 是多行而不是单行
我该如何解决?
谢谢。

回答by Shwed_Berlin

Per default the Textbox is singleline. Maybe you have defined some Style for Textbox?

默认情况下,文本框是单行的。也许您已经为文本框定义了一些样式?

Try to set TextWrapping="NoWrap"and AcceptsReturn="False"for your TextBox

尝试为您的 TextBox设置TextWrapping="NoWrap"AcceptsReturn="False"