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
295
Grid Row Color
posted

I have a requirement where my grid row color is determined by a cell value within that row.  I have implemented that with the following code:

        <DockPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ClipToBounds="True">

                <igDP:XamDataGrid Margin="10,0,20,0" Name="xamDataGrid_POC"  DataSource="{Binding}" MinHeight="200" MaxHeight="300"  VerticalAlignment="Top" Width="Auto" RecordsDeleting="xamDataGrid_POC_RecordsDeleting" RecordUpdated="xamDataGrid_POC_RecordUpdated" RecordAdded="xamDataGrid_POC_RecordAdded" RecordAdding="xamDataGrid_POC_RecordAdding" FieldLayoutInitialized="ig_FieldLayoutInitialized" FieldPositionChanged="ig_FieldPositionChanged" RecordUpdating="xamDataGrid_POC_RecordUpdating" Loaded="xamDataGrid_POC_Loaded" LayoutUpdated="xamDataGrid_POC_LayoutUpdated" CellChanged="xamDataGrid_POC_CellChanged" CellUpdated="xamDataGrid_POC_CellUpdated" EditModeStarting="xamDataGrid_POC_EditModeStarting"   DataContext="{Binding}" BorderThickness="2" BorderBrush="Black" SnapsToDevicePixels="True">

                        <igDP:XamDataGrid.FieldLayoutSettings>

                              <igDP:FieldLayoutSettings HighlightAlternateRecords="False"/>

                        </igDP:XamDataGrid.FieldLayoutSettings>

 

                        <igDP:XamDataGrid.Resources>

 

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

                            <Setter Property="BorderThickness" Value="0,0,1,1"/>

                            <Setter Property="BorderBrush" Value="Black"/>

                        </Style>

 

 

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

                            <Style.Triggers>

                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.POCPriorityValue}" Value="High">

                                    <Setter Property="BackgroundAlternate" Value="Red" />

                                    <Setter Property="Background" Value="Red" />

                                </DataTrigger>

                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.POCPriorityValue}" Value="Medium">

                                    <Setter Property="BackgroundAlternate" Value="Yellow" />

                                    <Setter Property="Background" Value="Yellow" />

                                </DataTrigger>

                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.DataItem.POCPriorityValue}" Value="Low">

                                    <Setter Property="BackgroundAlternate" Value="Green" />

                                    <Setter Property="Background" Value="Green" />

                                </DataTrigger>

                            </Style.Triggers>

                        </Style>

                    </igDP:XamDataGrid.Resources>

                </igDP:XamDataGrid>

 

The problem is that the row color is not added when rows are inserted.  However, if I scroll the grid so the new row rolls off the screen and then scroll it back down the row is colored properly.

 

How can I force the row to draw the correct color immediately upon being inserted into the grid?

 

 

 

Parents
  • 7305
    Suggested Answer
    posted

    Hello,

    I recommend different approach; using a converter. I am attaching a sample that demonstrates it with converter. The sample contains a button to add a record, and adding a record with user entry is available as well. With the button, you can select any record and click 'Add' that would duplicate that record. Without record selection it will add a blank record. Depending on the value on the second column called "Rating", the background will be styled using the converter.

    Please test it and let me know if you have any question.

    Thank you,

    Sam

    XamDataGrid_AddRow.zip
Reply Children