建立在我的应用程序文本框中的文字,我创建在运行时的文本框,这里是代码获取通过在运行时
TextBox bt = new TextBox();
bt.Name = "population_textbox";
bt.Height = 20;
bt.SetValue(Grid.ColumnProperty, 1);
bt.SetValue(Grid.RowProperty, 0);
temp_grid.Children.Add(bt);
那么,如何得到这个文本框的文本后用户键入内容并输入。我不知道怎么办呢,我试着
var tb = (FrameworkElement)this.FindName("population_textbox") as TextBox;
Console.Write(tb.Text);
这是错误警报:
Exception has been thrown by the target of an invocation.
Console.Write(((FrameworkElement的)这个.FindName(“population_textbox”)as TextBox).Text.ToString()); – zey 2013-04-08 09:15:40
'temp_grid'是否有一个名为'FindName(..)'的方法?如果是,请尝试调用它而不是'this.FindName(..)' – 2013-04-08 09:16:12
@zey:结果相同,异常已被抛出 – duykhoa 2013-04-08 09:19:23