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.

Parents
  • 35319
    Verified Answer
    posted

    Hi Vamshi,

     

    Thank you for your post. I have been looking into your requirement and my suggestion is to bind the ‘Background’ property of the CellValuePresenter like e.g.:

     

                <Style TargetType="{x:Type igDP:CellValuePresenter}">

                    <Setter Property="Background" Value="{Binding Value, RelativeSource={RelativeSource Self}, Converter={StaticResource BackGroundConverter}}"/>

                </Style>

     

    This way you are able to access the cell value. I am attaching a sample application(DataGridDataRowTable.zip) that shows my approach.

     

    Let me know, if you need any further assistance on this matter.

    DataGridDataRowTable.zip
Reply Children
No Data