c# - 顶部垂直对齐的多行文本框

标签 c# .net wpf xaml textbox

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

我有:

<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"/>

但是文本垂直居中,我似乎找不到用于垂直对齐的 TextAlignment 属性。

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

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

最佳答案

经过评论讨论后。这就是答案:

<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"/>

任何问题都应该得到解答! :)

关于c# - 顶部垂直对齐的多行文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13724183/

相关文章:

c# - 如何在 blazor 中手动渲染父组件的 razor 代码?

.net - 在 key 环中找不到 key 。无法验证 token

.net - 如何在 VB.Net 中拆分复杂的字符串

c# - 如何在运行时将对象转换为可为空的 double?

c# - C# : Where in the code to set SSL Keystore Password? 中的 Websphere MQ

c# - System.InvalidCastException C#

c# - 向 RDLC 报告添加新数据集时 Visual Studio 挂起

c# - 我该如何解决有关 TcpListener : Please use TcpListener(IPAddress localaddr, int port) 的警告?

c# - 使用 WCF 的三层架构

wpf - 在WPF中创建一个不错的GUI