How to change background color of DataGrid cell based on cell value

I am trying to change the color of Backgroundmy DataGridcells containing the word "Change".

In WinFormsI did this with this code:

DataGridViewCellStyle style = new DataGridViewCellStyle();
style.BackColor = Color.DarkCyan;

foreach (DataGridViewRow Row in dataGridView1.Rows)
{
    if (Row.Cells["Permission"].Value.ToString().Contains("Modify"))
    {
        Row.Cells["Permission"].Style = style;
    }
}

I fill this one DataGridwith DataTable.

I know very little about WPF, so if you have any suggestions please be very specific.

+3
source share
1 answer

I did the following to fix my problem:

<DataGrid x:Name="dataGrid" HorizontalAlignment="Left" Height="173" Margin="53,127,0,0" VerticalAlignment="Top" Width="378" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridCheckBoxColumn Binding="{Binding Selecione}" Header="Selecione"/>
                <DataGridTextColumn Binding="{Binding Grupos}" Header="Grupos"/>
                <DataGridTextColumn Binding="{Binding Permissoes}" Header="Permissões">
                    <DataGridTextColumn.CellStyle>
                        <Style TargetType="DataGridCell">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Permissoes}" Value="Modify">
                                    <Setter Property="Background" Value="Green"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </DataGridTextColumn.CellStyle>
                </DataGridTextColumn>`enter code here`
            </DataGrid.Columns>
        </DataGrid>
+1
source

All Articles