<ListView ItemsSource="{Binding}" Name="myView">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding fieldA}" Header="Field A" />
<GridViewColumn DisplayMemberBinding="{Binding fieldB}" Header="Field B" /> </GridView>
</ListView.View>
</ListView>
I would like to know how to format my list view so that if object.fieldA == "apples", the font is red in the fieldA cell.
Thanks boffins.
You need to use a DataTemplate
to show the fieldA
value and add a trigger changing the Foreground
property for a given value.
See also Data Templating Overview on MSDN.
<GridViewColumn Header="Field A">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="Txt" Text="{Binding fieldA}" />
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding fieldA}" Value="apples">
<Setter TargetName="Txt" Property="Foreground" Value="Red" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With