Articles in this section
Category / Section

How to apply animation for the selected rows in Xamarin.iOS DataGrid?

3 mins read

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.   

grid.SelectionController = new CustomSelectionController(grid);
grid.SelectionMode = SelectionMode.Multiple;

 

public class CustomSelectionController : GridSelectionController
{
   public UIColor[] SelectionColors { get; set; }
   public CustomSelectionController(SfDataGrid datagrid)
   {
      this.DataGrid = datagrid;
      SelectionColors = new UIColor[11] 
      {
         UIColor.Orange,
         UIColor.FromRGB(201,93,55),
         UIColor.FromRGB(123,149,52),
         UIColor.Red, UIColor.Black, 
         UIColor.Brown, 
         UIColor.FromRGB(42,159,214),
         UIColor.Gray,
         UIColor.FromRGB(24,123,67),
         UIColor.Purple,
         UIColor.FromRGB(72,173,170)
      };
   }
                                
   public override UIColor GetSelectionColor(int rowIndex, object rowData)
   {
      if (SelectionColors != null && rowIndex != -1)
                   return SelectionColors[rowIndex % 11];
      else
                   return UIColor.Blue;
   }
 
   protected override void SetSelectionAnimation(VirtualizingCellsControl rowElement)
   {
      rowElement.Alpha = 0.5f;
      UIView.Animate(2.0,0,UIViewAnimationOptions.CurveLinear,() =>
      {
                   rowElement.Alpha = 1f;
      },null);
   }
}

 

Refer the following screenshot that shows the final outcome upon execution of the above code.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied