Take the 2-minute tour ×

I have seen similar posts like this

However, they don't seem to answer my question. I have a XAML datagrid in a WPF application

<DataGrid AutoGenerateColumns="True" Grid.Row="1" AlternationCount="2" HeadersVisibility="Column" Name="dgSkillsMatrix" Margin="0,0,0,1" HorizontalGridLinesBrush="White" VerticalGridLinesBrush="White" AlternatingRowBackground="#FFD0D0EB" RowBackground="#FFECECF5" FontSize="12">
        <Style TargetType="{x:Type DataGridCell}">
                <DataTrigger Binding="{Binding Value}" Value="1">
                <DataTrigger Binding="{Binding Content}" Value="2">
                <DataTrigger Binding="{Binding Text}" Value="1">
                <DataTrigger Binding="{Binding Name}" Value="Temp">

As you can see, I have tried a number of different ways to "Trigger" the colour change, but none of them fire. If I put a generic setting in abouve the triggers it will change the colour.

I think the problem is that I am binding to the datagrid from a dynamic set of data that could change day to day, so I am using a datatable (below), as there is a varying number of coulmns that mean I can't use objects for each row, as I never know when the number of columns/properties would change.

this.dgSkillsMatrix.ItemsSource = (dt as IListSource).GetList();

I just need to know how to fire a trigger to change properties depending on that value of a cell created from a datatable to listsource.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Does this link offer any assistance? It appears that binding to a DataTable may cause a few issues for cell colouring, have you tried implementing a data converter and MultiDataBinding as the article suggests?

share|improve this answer
Yes, that's great Alex. But I am still getting an error: Value produced by BindingExpression is not valid for target property.; Value='#FFFFFFFF' MultiBindingExpression:target element is 'DataGridCell' (Name=''); target property is 'Background' (type 'Brush') –  markmcgookin Dec 9 '11 at 16:07
Try to wrap the value in a SolidColorBrush: new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); –  Baboon Dec 9 '11 at 16:21
Yeah mate, that was the issue. This works: return new SolidColorBrush((System.Windows.Media.Color)System.Windows.Media.ColorConverter.‌​ConvertFromString("#FFFF66")); –  markmcgookin Dec 9 '11 at 16:35
add comment

Your Answer


