日期:2014-05-18  浏览次数:21016 次

wpf中gird.findname的问题
private void Window_Loaded(object sender, RoutedEventArgs e)
  {
  Button btnAdd = new Button();
  btnAdd.Name = "Add";
  btnAdd.Content = "Add";
  btnAdd.Click +=new RoutedEventHandler(btnAdd_Click);
  gdGrid.Children.Add(btnAdd);

  Button myButton = gdGrid.FindName("Add") as Button; //取不到,在btnAdd_Click中也取不到
  }

高人指点下

或者给个思路也好哈

------解决方案--------------------
你可以这样做
int indexbtnAdd = this.gdGrid.Children.IndexOf(btnAdd);
this.gdGrid.Children[indexbtnAdd]
就是你要的Button了
@#@