Question: How to refresh SfDataGrid to force DataTriggers in GridTemplateColumn to reevaluate

We are using DataTriggers in GridTemplateColumns like documented here:

https://www.syncfusion.com/kb/6785/how-to-load-different-images-in-gridcell-based-on-cell-value-in-wpf-datagrid-sfdatagrid

We use an ObservableCollection as ItemsSource, the collection elements are plain objects without INotifyPropertyChanged (Database models). We modify data inside of the collection elements, and use SfDataGrid.View.Refresh to force a refresh on the view to present the changes. All Column types refresh their data as expected, except for this one:


<sf:GridTemplateColumn HeaderText="Freigabe">

    <sf:GridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Image Margin="5 0 5 0" Width="16" Height="16" VerticalAlignment="Center" HorizontalAlignment="Center">
                <Image.Style>
                    <Style TargetType="{x:Type Image}">
                        <Style.Setters>
                            <Setter Property="Source" Value="{x:Null}"/>
                        </Style.Setters>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=Bestellung.IstFreigegeben}" Value="True">
                                <Setter Property="Source" Value="{StaticResource IconOkSmall}"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=Bestellung.IstGesperrt}" Value="True">
                                <Setter Property="Source" Value="{StaticResource IconOnHoldSmall}"/>
                            </DataTrigger>
                            <DataTrigger Binding="{Binding Path=Bestellung.IstFreigabeAusständig}" Value="True">
                                <Setter Property="Source" Value="{StaticResource IconHourglassSmall}"/>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </Image.Style>
            </Image>
        </DataTemplate>
    </sf:GridTemplateColumn.CellTemplate>
</sf:GridTemplateColumn>


We assume that the DataTriggers are not executed on the cell,and the cell content stays the same as before the refresh.The binding has a different value.Whatdo we need to do to have above cell to correctly refresh itself with updating based on the StyleTriggers.We want to prevent using a Converter,asfor code maintenance it is more efficient for us to useDataTriggers.Thanksfor your suggestions.


1 Reply

VS Vijayarasan Sivanandham Syncfusion Team June 14, 2022 04:46 PM UTC

Hi Michael Pillwax,

We have prepared the simple sample based on a provided code snippet and checked the reported problem from our end. The reported problem only occurs without the implementation of INotifyPropertyChanged in the underline model. If we implement the INotifyPropertyChanged for the underline model object, the images are properly updated at runtime. Please find the tested sample in the attachment. Can you please share the details about not implementing the INotifyPropertyChanged in the underline model?

It will be helpful for us to check on it and provide you with the solution at the earliest.

Regards,
Vijayarasan S


Attachment: Sample_e80a655b.zip

Loader.
Up arrow icon