4

如何在 VS 2012 WPF 应用程序中将数据触发器应用于以下内容?

我试过这个:错误:前景不可访问或识别

                <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>

我希望它以不同的颜色显示未找到标题

                <DataTrigger Binding="{Binding Title}" Value="{x:Null}">
                    <Setter Property="Foreground" Value="Salmon"/>
                </DataTrigger>
4

1 回答 1

8

您必须指定 的类Foreground,您必须省略DisplayMemberBinding并使用例如 a TextBlockinDataTemplate代替:

<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>
于 2013-07-16T17:22:22.937 回答