举例说明:动态添加一个TextBox到Grid中,并设置它的Margin:
TextBox text = new TextBox();
t_grid.Children.Add(text);
Thickness margin = new Thickness(left, top, right, bottom);
text.Margin = margin;