How do you bind a grid's children to a list?
Use an ItemsControl
with the ItemsPanel
set to a Grid :
<ItemsControl ItemsSource="{Binding TheList}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <Grid/> </ItemsPanelTemplate> </ItemsControl.ItemsPanel></ItemsControl>
In the ItemsControl
's ItemContainerStyle
, you might want to bind the Grid.Row
and Grid.Column
attached properties to some property of the items :
<ItemsControl.ItemContainerStyle> <Style TargetType="{x:Type FrameworkElement}"> <Setter Property="Grid.Row" Value="{Binding RowIndex}"/> <Setter Property="Grid.Column" Value="{Binding ColumnIndex}"/> </Style> </ItemsControl.ItemContainerStyle>