Problem changing the Foreground colour of a WPF DataGrid Cell using MultiBinding

I am trying to change the Foreground colour of a DataGridCell, NOT the entire row, given the value of the specific cell contents. For example, if the date value of the cell is out of date then I want to set the Foreground to red. I am almost where I am using MultiBinding to extract two values from the data grid and parsing it through value converter which implements IMultiValueConverter.

In short, and without then need to go into the converter itself, I have written the following XAML: `

    <Style x:Key="CellHighlighterStyle">
        <Setter Property="my:ExtendedDataGrid.Foreground">
            <Setter.Value>
                <MultiBinding Converter="{StaticResource cellHighlighterConverter}">
                    <MultiBinding.Bindings>
                        <Binding RelativeSource="{RelativeSource self}"/>
                        <Binding Path="Row" Mode="OneWay"/>
                    </MultiBinding.Bindings>
                </MultiBinding>
            </Setter.Value>
        </Setter>            
    </Style>

I then added to my Datagrid : CellStyle="{StaticResource CellHighlighterStyle}"`.

Now, my converter sees the first Value[0] property as the DataGridCell but the second value is some sort of made up DependencyProperty. It's like it has created a default or dummy property when I actually want to get the row. In fact, I would really like to get the class object associated to that row. My DataGrid is bound to a List<of a class object> .

I am sure that I am inches away. How do I parse either the DataGrid Row so that I can extract the value of the field, or the object bound to that row or column itself in order for me to return the colour I want to return? OR, is there a better way for me to selectively alter the properties of a DataGrid Cell given the value?


The DataContext of the cell should be the data-object of the row, try changing the second binding to this:

<Binding />

Which binds directly to the DataContext.

链接地址: http://www.djcxy.com/p/71116.html

上一篇: 从Silverlight 4中的代码隐藏中更改DataGridCell的背景

下一篇: 使用MultiBinding更改WPF DataGrid单元格的前景色时出现问题