ColumnDefinition column = new ColumnDefinition();
column.Width = System.Windows.GridLength.Auto;

layoutRoot.ColumnDefinitions.Add(column);

layoutRoot.Children.Add(btnTest);
Grid.SetColumn(btnTest, (layoutRoot.ColumnDefinitions.Count-1));

————————————————

In Silverlight, if we want to dynamically add controls to our page, we may think in this way:

  • <Grid> : so we can add columns, rows by using Grid.SetColumn(<elementToAdd>,<columnNumber>)
  • <StackPanel>: So we can set the orientation (Vertical or Horizontal) of the elements we add in that stackpanel
Advertisement