Question

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>
Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top