开发者

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}"/>开发者_如何学C
    </Style>
  </ListView.ItemContainerStyle>

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

lvItems.ItemsSource = list of { Description, Color } 

What am I doing wrong?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜