访问网元编程
问题描述:
比方说,我有:访问网元编程
<Grid Name="paramGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" Grid.Column="0"/>
<TextBox Grid.Row="1" Grid.Column="0"/>
</Grid>
我知道怎么行/列添加诸如:以上
paramGrid.RowDefinitions.Add(new RowDefinition());
TextBox tb = new TextBox();
tb.Text = "Sample";
tb.Name = "textBox";
paramGrid.Children.Add(tb);
Grid.SetColumn(tb, 0);
Grid.SetRow(tb, 2);
将增加一个TextBox到新行。
我的问题是:我现在怎么去访问它?我需要在新行上查询TextBox
的.Text
属性。
答
保持一个裁判的文本框:
private TextBox m_Tb;
...
m_Tb = new TextBox();
m_Tb.Text = "Sample";
m_Tb.Name = "textBox";
....
something something = m_Tb.Text;
搜寻电网的Children
收藏:
var tb = (TextBox)paramGrid.Children[0];
something something = tb.Text;
显然[0]
如果文本框或者是在网格中唯一的孩子只会工作或第一个。