Uniform grid in ItemPanel template
Let's say I have something like this code
<ItemsControl ItemsSource="{Binding Blabla}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="8" Columns="8"></UniformGrid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<Data Template>
<Button Command="{Binding blablaComamnd}"></Button>
</DataTemplate>
From what I understand, the uniformgrid will map 64 buttons in a wrapper, for example to the blabla command of an object inside the blalbla data structure. Is there anyway, specify which item is sent to which coordinates in the grid? (based on binding to some data in the blabla object)
Thank you so much
source to share
If you want to specify which element goes into the cell, you need to use normal Grid
and change ItemContainerStyle
for ContentPresenter
, which is the wrapper for the elements for ItemsControl
, for binding, Grid.Row
and Grid.Column
for your viewmodel
<ItemsControl ItemsSource="{Binding Blabla}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
</Grid>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Command="{Binding blablaComamnd}"></Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<Setter Property="Grid.Column" Value="{Binding Column}"/>
<Setter Property="Grid.Row" Value="{Binding Row}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
where Column
and Row
are properties of the same view model containingblablaComamnd
source to share