开发者

How do I assign a StackPanel to a specific Grid row/column in code (not XAML)?

开发者 https://www.devze.com 2022-12-25 11:04 出处:网络
Given this XAML: <StackPanel Orientation=\"Horizontal\" Grid.Row=\"1\" Grid.Column=\"0\" Margin=\"5\">

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号