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>
精彩评论