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
30
Change Cell and Row Color when cell updated
posted

Hello,

I have a DataGrid with a dataSource binding to a collection.

A trigger with a CellUpdated event.

The method that is called as soon as you make a change to the cell is in my ViewModel.

I want to change the color of the cell and row concerned as soon as there is change

.xaml :



   
       
             

       

   

.cs :

public void XamDataGridCellUpdated(object sender, CellUpdatedEventArgs e)
{

       var xamDataGrid = sender as XamDataGrid;

}

How could I do ?

Thanks for any thoughts.

Parents
  • 30
    Verified Answer
    posted

    Hello,

    Sorry, I forgot .xaml

    Hello,

    I have a DataGrid with a dataSource binding to a collection.

    A trigger with a CellUpdated event.

    The method that is called as soon as you make a change to the cell is in my ViewModel.

    I want to change the color of the cell and row concerned as soon as there is change

    .xaml :

    <igDP:XamDataGrid Name="XamDataGridTableData" DataSource="{Binding TableData}">
         <i:Interaction.Triggers>
              <i:EventTrigger EventName="CellUpdated" x:Name="interactivityFix" SourceName="XamDataGridTableData">
                   <ei:CallMethodAction x:Name="interactionsFix" MethodName="XamDataGridCellUpdated" TargetObject="{Binding}"/>
              </i:EventTrigger>
         </i:Interaction.Triggers>
    </igDP:XamDataGrid>

    .cs :

    public void XamDataGridCellUpdated(object sender, CellUpdatedEventArgs e)
    {

           var xamDataGrid = sender as XamDataGrid;

    }

    How could I do ?

    Thanks for any thoughts.

  • 16495
    Verified Answer
    Offline posted in reply to Lepage

    Hello Lepage,

    You can use the approach from the following forum thread in order to change the cell background:

    https://ko.infragistics.com/community/forums/t/14111.aspx

    1. Use the Tag property on the Cell, so in the CellUpdated event set Cell.Tag to a Boolean true .
    2. Bind the Tag of the CellValuePresenter to a multibinding that binds to the CellValuePresenter's Field and Record
    to obtain the Cell and then set the CellValuePresenter style trigger to bind to the Tag.Tag(i.e. Cell.Tag) .


    <Style TargetType="{x:Type igDP:CellValuePresenter}">
                <Setter Property="Tag">
                    <Setter.Value>
                        <MultiBinding Converter="{StaticResource fieldRecordToCell}">
                            <Binding RelativeSource="{RelativeSource Self}" Path="Field" />
                            <Binding RelativeSource="{RelativeSource Self}" Path="Record" />
                        </MultiBinding>
                    </Setter.Value>
                </Setter>
                <Style.Triggers>
                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Tag.Tag, Converter={StaticResource keepChangedCellStyle}}" Value="True" >
                        <Setter Property="Background"  Value="Yellow"/>
                    </DataTrigger>
                </Style.Triggers>
    </Style>

    I have attached a simple sample application, where you can test this approach.

    Let me know if you have any questions.

    Sincerely,
    Zhivko
    Associate Software Developer

    CellUpdated_Background.zip
Reply Children
No Data