wpf动态创建控件后 指定到容器的具体位置


private void Window_Loaded(object sender, RoutedEventArgs e)
{
Button button5 = new Button();
button5.Click += Button5_Click;
button5.Height = 50;
button5.Width = 50;
button5.Name = "Button6";
button5.Content = "动态狗";
grid1.Children.Add(button5);
button5.SetValue(Grid.RowProperty, 2);//设置到Grid对应的行
button5.SetValue(Grid.ColumnProperty, 2);//设置到Grid对应列

}

private void Button5_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("我是动态加载出来的呢");
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM