一
ValueConverter
会起作用。另一种选择是使用
DataTrigger
在风格上
ListBoxItem
. 可能是这样的:
<Style x:Name="MinDateTimeListBoxStyle" TargetType="ListBoxItem">
<Style.Triggers>
<Setter Property="Background" Value="Gray" />
<DataTrigger Binding="{Binding Path=Done}"
Value="{x:Static sys:DateTime.MinValue}">
<Setter Property="Background" Value="White" />
</DataTrigger>
</Style.Triggers>
</Style>
当
Done
不是
DateTime.MinValue
. 我认为没有一种方法可以在触发器中进行不等于比较,因此它默认将背景设置为灰色,并且仅在
多恩
还没有改变。最好是为背景使用正确的颜色,而不是白色(可能得到父级背景的值?)但是这应该给你一些开始的东西。
更新
:若要仅将此样式应用于特定列表框的项,请为该样式命名并设置
ItemContainerStyle
酌情:
<ListBox x:Name="StyledListBox"
ItemContainerStyle="{StaticResource MinDateTimeListBoxStyle}" />
<ListBox x:Name="NormalListBox" />