У меня есть класс Cell со свойством Color, и я создаю список объектов List of Cell, который я планирую использовать в качестве источника привязки для UniformGrid. Ячейки в равномерной сетке должны менять цвет в зависимости от свойства объекта Color, однако, как бы я ни писал код xaml, он не меняется. Я также пытался поместить ячейки в ObservableCollections, но это не работает, просто отображается как GameOfLife.Cell в окне.
У меня есть этот код xaml:
<DataTemplate x:Key="Line">
<ItemsControl ItemsSource="{Binding}" ItemTemplate="{DynamicResource CellTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</DataTemplate>
<DataTemplate x:Key="CellTemplate">
<DataGridCell Content="{Binding}" Background="{Binding Color}"></DataGridCell>
</DataTemplate>
</Window.Resources>
<UniformGrid Background="Red">
<ItemsControl x:Name="Cells" ItemTemplate="{DynamicResource Line}"/>
</UniformGrid>
И вот как я пытался связать объекты ячеек:
public MainWindow()
{
InitializeComponent();
ObservableCollection<ObservableCollection<Cell>> cells = new ObservableCollection<ObservableCollection<Cell>>();
cells.Add(new ObservableCollection<Cell> { new Cell(State.Alive), new Cell(), new Cell(State.Alive) });
cells.Add(new ObservableCollection<Cell> { new Cell(State.Alive), new Cell(), new Cell() });
cells.Add(new ObservableCollection<Cell> { new Cell(), new Cell(State.Alive), new Cell() });
Cells.ItemsSource = cells;
}
Неявное состояние ячейки - State.Dead.
Я хочу знать, почему это не работает и как заставить это работать.