C# 在数据网格中为ItemSource设置为数据表的单元格着色

C# 在数据网格中为ItemSource设置为数据表的单元格着色,c#,wpf,datagrid,datatable,C#,Wpf,Datagrid,Datatable,我有一个数据表,通过将数据网格的ItemsSource属性指定为 this.heatMap.ItemsSource = heatMapTable.DefaultView; 其中,heatmap是DataGrid,heatMapTable是DataTable。 我的问题是如何从这个数据网格中选择一个单元格,并在特定条件下对其进行着色。我知道我不能给数据表上色。请帮助..使用数据触发器检查您的状况。Eg <Style TargetType="DataGridCell">

我有一个数据表,通过将数据网格的ItemsSource属性指定为

this.heatMap.ItemsSource = heatMapTable.DefaultView;
其中,heatmap是DataGrid,heatMapTable是DataTable。
我的问题是如何从这个数据网格中选择一个单元格,并在特定条件下对其进行着色。我知道我不能给数据表上色。请帮助..

使用数据触发器检查您的状况。Eg

   <Style TargetType="DataGridCell">
        <Style.Triggers>
            <DataTrigger Binding="{Binding Area}" Value="12345">
                <Setter Property="Background" Value="Yellow"/>
            </DataTrigger>
        </Style.Triggers>
    </Style>


您可以为DataGridCell编写一个样式,以基于DataTrigger应用背景色。否,在特定条件下,例如,如果单元格包含内容“y”,我想将DataTable中DataRow的所有单元格都涂成黄色。我收到一个错误“使用ItemsSource之前,items集合必须为空”怎么做?如何使用DataGrid,显示XAML代码。