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
- <Grid> and <StackPanel> can add other grids or stacks inside them using <…>.Children.Add(..) method.
- Also take a look at the post How to find all Textboxes on a Silverlight page for more helpful tips.
Advertisement
