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