Vincent

Vincent

  • NA
  • 1
  • 0

Custome foreground color of selected item in ListView

Mar 9 2009 10:36 AM
I'm writing a listview:
<StackPanel Margin="8">
<ListView Name="listView" ItemsSource="{Binding}">
<ListView.View>
<GridView>
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}" />
<GridViewColumn Header="Age" DisplayMemberBinding="{Binding Age}" />
<GridViewColumn Header="Grade">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Grade}" Foreground="{Binding GradeColor}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</StackPanel>

The foreground color of column 'Grade' is decided by the property GradeColor. It can be Green, Yello and Red.

When I select an item in the listview, the background color of the selected item turned to blue, and the foreground color of the first two column turned to white, but the foreground of the 'Grade' column didn't change to white, which cause the text is unreadable when the item is selected.

Is there any way that I can make the foreground of the 'Grade' column to be white like the other columns when the item is selected? Thx!

Answers (1)