I have the following Grid in XAML:
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<ItemsControl ItemsSource="{Binding ListOfWords}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Grid.Column="{Binding xAxis}" Grid.Row="{Binding yAxis}" Text="{Binding wordDisplay}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
The above does not work as expected, instead, It just shows all the items of the list in the first cell. How can I bind each word to a different cell in this Grid based off of the 'X' and 'Y' positions?
-- MainViewModel --
public class MainViewModel : ViewModelBase
{
private ObservableCollection<Word> _word;
public IEnumerable<Word> ListOfWords => _word;
public MainViewModel()
{
_word = new ObservableCollection<Word>()
{
// xAxis, yAxis, wordDisplay
new Word(0,0,"aaa"),
new Word(0,3,"bbb"),
new Word(6,8,"ccc"),
new Word(1,7,"ddd"),
new Word(3,3,"eee"),
new Word(9,2,"fff"),
new Word(6,1,"ggg"),
new Word(0,5,"hhh")
};
}
}
The List will start off empty and as it gets populated, items will need to show up on the Grid.