How to apply animation for the selected rows in SfDataGrid?
SfDataGrid provides support to select one or more rows either programmatically or by touch interactions. By default SfDataGrid does not apply any animation for the selected rows. However it provides extensibility to apply animation for the selected rows by writing a custom SelectionController derived from GridSelectionController and assigning it to the SfDataGrid.SelectionController property. You can override the SetSelectionAnimation () method in which you will get the selected row element as an argument. Thus you can apply animation for the selected row(s) in runtime based on your requirement.
Refer the following code example that explains how to apply a simple Alpha animation to the selected row.
sfGrid.SelectionController = new CustomSelectionController(sfGrid); sfGrid.SelectionMode = SelectionMode.Multiple;
public class CustomSelectionController : GridSelectionController { public Color[] SelectionColors { get; set; } public CustomSelectionController(SfDataGrid datagrid) { this.DataGrid = datagrid; SelectionColors = new Color[5] { Color.Red, Color.Blue, Color.Black, Color.Gray, Color.MediumPurple }; } public override Color GetSelectionColor(int rowIndex, object rowData) { if (SelectionColors != null) return SelectionColors[rowIndex % 7]; else return Color.Blue; } protected override void SetSelectionAnimation(VirtualizingCellsControl rowElement) { //Alpha animation rowElement.Alpha = 0.5f; rowElement.Animate().Alpha(0.5f).SetDuration(30000).AlphaBy(1f).WithEndAction(new Runnable(() => { rowElement.Alpha = 1f; })); } }
Refer the following screenshot that shows the final outcome upon execution of the above code.