1

我想根据一列中的值更新行颜色,我已经将 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>
4

1 回答 1

1

你快到了。只需DisplayMemberBinding从您的列中删除,因为一旦您已经提供给您的列,GridViewColumn您就不需要设置它。CellTemplate您不需要同时设置两者。

删除DisplayMemberBinding="{Binding Path=TransactStatus}",您的触发器将完美工作。

于 2013-11-03T18:33:03.070 回答