我想根据一列中的值更新行颜色,我已经将 ItemContainerStyle 应用于列表视图。
代码
<ListView KeyboardNavigation.TabIndex="3" x:Name="xListView"
SelectionMode="Extended" ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
DataContext="{Binding Path=FilteredItems}" ItemsSource="{Binding}"
GridViewColumnHeader.Click="ListViewHeader_Click"
Loaded="xListView_Loaded"
ItemContainerStyle="{StaticResource alternatingListViewItemStyle}"
AlternationCount="2"
MouseDoubleClick="xListView_MouseDoubleClick">
<ListView.View>
<GridView>
<GridViewColumn Header="{x:Static res:RecoveryManager.ColHeader_Name}"
DisplayMemberBinding="{Binding Path=Name}"
HeaderStringFormat="{}{0} "/>
<GridViewColumn Header="{x:Static res:AccountManager.ColHeader_ID}"
DisplayMemberBinding="{Binding Path=ID}"
HeaderStringFormat="{}{0} "/>
<GridViewColumn Header="{x:Static res:AccountManager.ColHeader_filename}"
DisplayMemberBinding="{Binding Path=filename}"
HeaderStringFormat="{}{0} "/>
<GridViewColumn Header="{x:Static res:AccountManager.ColHeader_TransactStatus}"
DisplayMemberBinding="{Binding Path=TransactStatus}"
HeaderStringFormat="{}{0} ">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="transType" Text="{Binding TransactStatus}"/>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding TransactStatus}"
Value="pending">
<Setter TargetName="transType" Property="Background"
Value="#FF0000" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>