How can I apply a datatrigger to the following in a VS 2012 WPF app?
I have tried this: Error: Foreground is not accessible or recognized
<ListView.View>
<GridView AllowsColumnReorder="true"
ColumnHeaderToolTip="Information">
<GridViewColumn DisplayMemberBinding= "{Binding Path=Title , TargetNullValue='No Title Found'}"
Header="Title" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Title}" Value="{x:Null}">
<Setter Property="Foreground" Value="Salmon"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
I want it to Display No Title Found in a different color
<DataTrigger Binding="{Binding Title}" Value="{x:Null}">
<Setter Property="Foreground" Value="Salmon"/>
</DataTrigger>
You have to specify the class of Foreground
, you have to omit DisplayMemberBinding
and use e.g. a TextBlock
in DataTemplate
instead:
<DataTemplate>
<TextBlock Text="{Binding Path=Title , TargetNullValue='No Title Found'}"/>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Title}" Value="{x:Null}">
<Setter Property="TextBlock.Foreground" Value="Salmon"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
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