堆栈面板和文本框以编程方式处于 for 循环中,只需更改边距即可。然后这些又被添加到 Window 上下文中。
现在,当用户在 TextBox 中输入值时,我需要将它们绑定到单独的字段。但是,由于某种原因,文本框未启用,我认为原因是字段未正确绑定。
StackPanel panel1 = new StackPanel();
for (int i = 0; i < 10; i++)
{
TextBox txtProgramValue1 = new TextBox();
txtProgramValue1.FontSize = 14;
txtProgramValue1.Height = 32;
txtProgramValue1.HorizontalAlignment = HorizontalAlignment.Right;
txtProgramValue1.VerticalAlignment = VerticalAlignment.Top;
txtProgramValue1.Width = 126;
txtProgramValue1.Margin = new Thickness(0, 51 + (i * 100), 16, 0);
txtProgramValue1.Name = "lblProgramValue" + i.ToString();
txtProgramValue1.IsEnabled = true;
panel1.Children.Add(txtProgramValue1);
}
我需要将每个 TextBox 的txtProgramValue1.Text映射到一个列表。