且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在动态创建的文本框的代码隐藏中将文本框的高度设置为自动

更新时间:2023-02-11 23:33:25

将您的 TextBox 包裹在 StackPanel 中.如果你通过代码来做,你可以做这样的事情,例如:

Wrap your TextBox in a StackPanel. If you're doing it via code, you could do something like this, for example:

public MainPage()
{
    InitializeComponent();

    var textBox = new TextBox
    {
        AcceptsReturn = true,
        Height = Double.NaN,
        TextWrapping = TextWrapping.Wrap
    };

    var stackPanel = new StackPanel();
    stackPanel.Children.Add(textBox);

    this.LayoutRoot.Children.Add(stackPanel);
}