wpf 顶部垂直对齐的多行文本框

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

A Multi-Line TextBox with Top Vertical Alignment

c#.netwpfxamltextbox

提问by Nick

I'm trying to create a multi-line TextBoxto allow the user to enter text.

我正在尝试创建一个多行TextBox以允许用户输入文本。

I have:

我有:

<TextBox Grid.Row="0"
    Height="107"
    ScrollViewer.VerticalScrollBarVisibility="Auto"
    ScrollViewer.HorizontalScrollBarVisibility="Disabled"
    AcceptsReturn="True"
    HorizontalAlignment="Left"
    Margin="164,80,0,0"
    VerticalAlignment="Top"
    Width="237"
    Text="{Binding Description, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" MaxLength="300" 
    TextWrapping="Wrap"/>

However the text is centered vertically and I can't seem to find a TextAlignmentproperty for vertical alignment.

然而,文本垂直居中,我似乎无法找到TextAlignment垂直对齐的属性。

I subsequently wrapped the textbox in a border and removed the Heightspecification, however when I click in the area below the textbox (but within the border) I would like the textbox to get focus and I can't seem to find a way to do this.

我随后将文本框包裹在边框中并删除了Height规范,但是当我单击文本框下方的区域(但在边框内)时,我希望文本框获得焦点,但我似乎无法找到一种方法来做到这一点.

Has anyone come across this issue before and found a solution?

有没有人以前遇到过这个问题并找到了解决方案?

回答by Kapitán Mlíko

So after discussion in comments. This is the Answer:

所以在评论中讨论之后。这是答案:

<TextBox Height="107"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
AcceptsReturn="True"
HorizontalAlignment="Left"
Margin="657,237,0,0"
VerticalAlignment="Top"
Width="237"
Text="Text alignment left and top" MaxLength="300" 
TextWrapping="Wrap" VerticalContentAlignment="Top" HorizontalContentAlignment="Left"/>

No question should be left unanswered! :)

任何问题都不应悬而未决!:)