I have a class:
public class TempClass
{
public int Row
{
get { return row; }
set { row = value; }
}
public int Column
{
get { return column; }
set { column = value; }
}
public string Value
{
get { return this.value; }
set { this.value = value; }
}
int row;
int column;
string value;
public TempClass(int row, int column, string value)
{
this.row = row;
this.column = column;
this.value = value;
}
}
I have created a List<TempClass> DummyCollection
and I have bound it to an ItemsControl
. The ItemsControl
uses a UniformGrid
panel for ItemsPanel
property. Here is the XAML code:
<ItemsControl ItemsSource="{Binding Path=DummyCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Rows="3" Columns="5" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate DataType="TempClass">
<Border>
<TextBlock Text="{Binding}" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I want to be able to bind TempClass
items to the particular cell in the ItemsControl
, i.e. I want to set the Grid.Row
and Grid.Column
properties of the item container to match Row
and Column
properties of the TempClass
items. How do I achieve that? Thanks.
<ItemsControl>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Grid.Row" Value="{Binding Row}"/>
<Setter Property="Grid.Column" Value="{Binding Column}"/>
</Style>
</ItemsControl.ItemContainerStyle>
...
</ItemsControl>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With