我想根据一列中的值更新行颜色,我已经将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>
答案 0 :(得分:1)
你快到了。只需从DisplayMemberBinding
中删除GridViewColumn
即可,因为您已经为列提供了CellTemplate
后无需进行设置。
您无需同时设置两者。
删除DisplayMemberBinding="{Binding Path=TransactStatus}"
,您的触发器将完美运行。