Andrew Florko
Andrew Florko

Reputation: 7750

How do I decorate ListView row depending on item property?

I bind List of items to WPF ListView and want to set row background/foreground depending on item property value. I have XAML like that but color doesn't applied:

<ListView x:Name="lvItems">
  <ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
      <Setter Property="Foreground" Value="{Binding Path=Color}"/>
    </Style>
  </ListView.ItemContainerStyle>

  <ListView.View>
    <GridView>
      <GridViewColumn DisplayMemberBinding="{Binding Path=Description}" Header="Description"/>
    ...

lvItems.ItemsSource = list of { Description, Color } 

What am I doing wrong?

Upvotes: 0

Views: 1873

Answers (1)

brunnerh
brunnerh

Reputation: 185082

You cannot bind a color to a brush-property (if your Color property actually is a color), it should be something like this:

<Setter Property="Foreground">
    <Setter.Value>
        <SolidColorBrush Color="{Binding Color}" />
    </Setter.Value>
</Setter>

Upvotes: 2

Related Questions