Reputation: 2724
I have a stackpanel in my XAML called MainStackPanel. Inside my XAML.CS I am programatically creating a few datagrids like this:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
var datagrid = new DataGrid();
// add some columns and stuff
}
This is just an example, in reality I am creating a dozen or so (depending on the results from the database).
I need to add them to my stackpanel (defined in my XAML file as follows:
<ScrollViewer Name="MainScrollViewer" Grid.Row="0">
<StackPanel Name="MainStackPanel">
// in here somehow
</StackPanel>
</ScrollViewer>
How can I programatically add my datagrids (in this case var datagrid) to the stackpanel (MainStackPanel)? Thanks,
Upvotes: 0
Views: 1053