Given this XAML:
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Margin="5">
How can I assign the Grid.Row and Grid.C开发者_如何学JAVAolumn attributes in (C#/VB) code?
StackPanel stackPanel = new StackPanel();
stackPanel.???
I think this is what you want:
MyStackPanel.SetValue(Grid.RowProperty, 1);
MyStackPanel.SetValue(Grid.ColumnProperty, 2);
Hope this helps
You should be able to do the following, where 'myGrid' is the name of your Grid control.
StackPanel stackPanel = new StackPanel();
Grid.SetColumn(stackPanel, 0);
Grid.SetRow(stackPanel, 1);
myGrid.Children.Add(stackPanel);
精彩评论