We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to animate the GridCell when the underlining property gets changed in SfDataGrid?

Platform: UWP |
Control: SfDataGrid

In SfDataGrid, you can animate the cell background when changing the underlining property by writing the behavior for the Grid inside the DataTemplate of column.

The following code example explains how to add Behavior inside the DataTemplate of column in SfDataGrid.Columns that animates the background of the column when you change the underlying property.


<!—Defining SfDataGrid-->
<syncfusion:SfDataGrid x:Name="datagrid"
                                ItemsSource="{Binding Stocks}">
<!—Add Behavior in SfDataGrid.Columns for specific column-->
    <syncfusion:GridTextColumn Width="200" MappingName="Change">
                <Grid Width="200">
                        <ColumnDefinition />
                        <ColumnDefinition />
                    <TextBlock x:Name="changeValue"
                                    Foreground="{Binding Change,                                                   Converter={StaticResource changeForegroundConverter}}"
                                    Text="{Binding Change}" />
                    <Path Width="18"
                                Data="{Binding Change,
                                                Converter={StaticResource stockChangeConverter}}"
                                Fill="{Binding Foreground,
                                    <RotateTransform Angle="0" />
                                    <ScaleTransform ScaleX="1" ScaleY="1" />


You can define the ColorAnimation to animate the column and create the Storyboard for changing the Background property of Grid for DataTemplate of column. The background color of Grid is animated by using the property changed event.

The following code example explains the AnimatedBehaviour of a changed Background of a column when the underling ViewMode property gets changed.


public class AnimateBehavior : Behavior<Grid>
    public string Property { get; set; }
    public ColorAnimation ColorAnimation { get; set; }
    public Brush BackgroundBrush { get; set; }
    protected override void OnAttached()
        BackgroundBrush = new SolidColorBrush { Color = Colors.Transparent };
        AssociatedObject.Background = BackgroundBrush;
        this.AssociatedObject.DataContextChanged += AssociatedObject_DataContextChanged;
    void AssociatedObject_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)
        BackgroundBrush = new SolidColorBrush { Color = Colors.Transparent };
    void WireEvents()
        var data = this.AssociatedObject.DataContext as INotifyPropertyChanged;
        if (data != null)
            data.PropertyChanged += data_PropertyChanged;
      // PropertyChanged event of SfDataGrid  
    void data_PropertyChanged(object sender, PropertyChangedEventArgs e)
        if (e.PropertyName.Equals("Change"))
            //Defining ColourAnimation
            ColorAnimation = new ColorAnimation
                From = Colors.Transparent,
                To = Colors.White,
                Duration = new Duration(TimeSpan.FromMilliseconds(400)),
                AutoReverse = true,
                FillBehavior = FillBehavior.Stop
            //Creating Storyboard for Animate the Background color of the GridCell
            Storyboard.SetTarget(ColorAnimation, AssociatedObject.Background);
            Storyboard.SetTargetProperty(ColorAnimation, "(Path.Color)");
            Storyboard sb = new Storyboard();
    protected override void OnDetaching()
        if (this.AssociatedObject.DataContext == null) return;
        var data = this.AssociatedObject.DataContext as INotifyPropertyChanged;
        if (data != null)
            data.PropertyChanged -= data_PropertyChanged;


The following screenshot displays the animated SfDataGrid.

Refer the following link for UWP code snippet


Refer the following link for UWP code snippet


Sample Links:



2X faster development

The ultimate UWP UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile