I have a ListView with a GridView in it:
<ListView x:Name="listViewPersons" ItemsSource="{Binding Path=Persons, Mode=OneWay}" IsSynchronizedWithCurrentItem="True"
Height="Auto" HorizontalAlignment="Stretch" Margin="4,4,4,4" Grid.Row="4" VerticalAlignment="Stretch" Width="Auto">
<ListView.View>
<GridView x:Name="gridViewPersons">
<GridViewColumn Header="Enabled">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<CheckBox HorizontalAlignment="Center" IsChecked="true" />
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}" Width="142" />
<GridViewColumn Header="Age" DisplayMemberBinding="{Binding Path=Age}" Width="142" />
<GridViewColumn Header="Gender" DisplayMemberBinding="{Binding Path=Gender}" Width="142" />
</GridView>
</ListView.View>
</ListView>
I want to be able to programmatically change each of the ListViewItems (or the rows in the grid) backgrounds or foregrounds to any color I want, for instance
listViewPersons.Items[0].Background = Brush.Red;
listViewPersons.Items[1].Background = Brush.Blue;
listViewPersons.Items[2].Background = Brush.Green
I know the previous lines of code don't work, but it pretty much explains what I want to achieve. Any help?
Thanks!