开发者

How do I decorate ListView row depending on item property?

开发者 https://www.devze.com 2023-03-08 15:34 出处:网络
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:

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

精彩评论

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