Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Applying DataTrigger To GridViewColumn

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>
like image 713
KeyboardFriendly Avatar asked Feb 15 '23 22:02

KeyboardFriendly


1 Answers

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>
like image 122
LPL Avatar answered Feb 24 '23 02:02

LPL