Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
Change background color of xamDataGrid cell based on cell value
posted

 

Hi,

My goal is to pass value to every cell in xamdatagrid to Converter. However, I do not know the column names of the DataSource (Datatable) bounded to the grid. XamDataGrid is bounded to DataTable.DefaultView iva view model. I do not know the columns of the datatable.

I have below style defined.

 <igWPF:XamDataGrid.Resources>                            
                            <Style TargetType="{x:Type igWPF:CellValuePresenter}" x:Key="BackGroundStyle">
                                <Setter Property="Background">
                                    <Setter.Value>
                                        <SolidColorBrush Color="{Binding Path=DataItem, Converter={StaticResource BackGroundConverter}}" />
                                    </Setter.Value>
                                </Setter>
                            </Style>

                        </igWPF:XamDataGrid.Resources>

 

Code Behind:

  private void xamDailyAudit_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e)
        {

            foreach (var field in e.FieldLayout.Fields)
            {
                field.Settings.CellValuePresenterStyle = xamDailyAudit.Resources["BackGroundStyle"] as Style;
            }

        }

 

The issue is, my converter is not firing when Path =  DataItem in style. If I add DataItem.columnname in style, then converter fires and cell background changes in XamDataGrid. How can I pass cell value to converter without knowing propertyname or column name.