我有一些为项目DatTrigger
设置文本颜色的 s 。ListView
如果我使用TextBox
它ItemTemplate
,ListView
它会完美运行。但如果我使用TextBlock
.
这段代码:
<Style TargetType="TextBox">
<Style.Triggers>
<DataTrigger Binding="{Binding Level,Mode=OneWay}"
Value="{x:Static Common:LoggingLevel.Error}">
<Setter Property="Foreground"
Value="Red" />
</DataTrigger>
<DataTrigger Binding="{Binding Level,Mode=OneWay}"
Value="{x:Static Common:LoggingLevel.Warning}">
<Setter Property="Foreground"
Value="Orange" />
</DataTrigger>
</Style.Triggers>
</Style>
...
<ListView ItemsSource="{Binding Entries}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Text,Mode=OneWay}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
生成正确颜色的消息列表。
虽然这段代码:
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Level,Mode=OneWay}"
Value="{x:Static Common:LoggingLevel.Error}">
<Setter Property="Foreground"
Value="Red" />
</DataTrigger>
<DataTrigger Binding="{Binding Level,Mode=OneWay}"
Value="{x:Static Common:LoggingLevel.Warning}">
<Setter Property="Foreground"
Value="Orange" />
</DataTrigger>
</Style.Triggers>
</Style>
...
<ListView ItemsSource="{Binding Entries}">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Text,Mode=OneWay}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
使用默认的黑色前景色呈现所有消息。