如何在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>
答案 0 :(得分:6)
您必须指定Foreground
的班级,您必须省略DisplayMemberBinding
并使用例如TextBlock
而DataTemplate
中的<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>
代替:
{{1}}