WPF 如果遍历Grid中所有控件??
------解决方案--------------------------------------------------------
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100" />
<RowDefinition Height="35"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
</Grid.ColumnDefinitions>
<Button x:Name="btnClick" Margin="50,0,50,0" Grid.Row="1" Grid.Column="0" Content="Click Me" Click="btnClick_Click" />
<Grid Grid.Row="0" Grid.Column="0" x:Name="Grid1">
</Grid>
</Grid>
public Window1()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Window1_Loaded);
}
void Window1_Loaded(object sender, RoutedEventArgs e)
{
RowDefinition rd = new RowDefinition();
Grid1.RowDefinitions.Add(rd);
//添加第0列
Border b = new Border();
b.BorderThickness = new Thickness(0, 0, 1, 1);
b.BorderBrush = Brushes.Black;
b.Name = "Border_" + (Grid1.RowDefinitions.Count - 1) + "_0";
TextBox tb = new TextBox();
string x = "TB_" + (Grid1.RowDefinitions.Count - 1) + "_0";
tb.Name = "TB_" + (Grid1.RowDefinitions.Count - 1) + "_0";
tb.BorderThickness = new Thickness(0);
tb.ToolTip = tb.Name;
b.Child = tb;//
b.SetValue(Grid.RowProperty, Grid1.RowDefinitions.Count - 1);
b.SetValue(Grid.ColumnProperty, 0);
Grid1.Children.Add(b);
}
private void btnClick_Click(object sender, RoutedEventArgs e)